Sei sulla pagina 1di 98

WEB CHAT SYSTEM

1. INTRODUCTION

This Project Entitled as ‘WEB CHAT’ is used basically for chatting purpose with the remote clients or users
on Internet or local networks. Here in this project a PHP client / server combination is used to chat with
remote users. When a Client wants to chat with a user on a remote host, he sends a request to the Server
with a identification name like chat-id, the server responds to the request by identifying the client-id which is
already registered in the server domain and when matched his request is granted and the client can begin to
chat with the remote users present on the internet or local network.
The power of Internet is such that it integrates together LANs located across diverse software and hardware
forms into a single large communication network that spans the globe. The client needs to have a client
software such as Netscape Navigator or chrome to retrieve information as well as chat on the www: WWW
is referred to as Netsurfing. And it supports chatting, text, video and audio.

It is important to understand the terms client/server because the WEB CHAT project is supported completely
by client/server model. A server is anything that has some resource that can be shared. There are compute
servers, which provide computing power, web servers, which store web pages. A client is simply any other
entity that wants to gain access to a particular server. The interaction between client\server is like an
interaction between an electrical socket and a lamp.

Web chat is now the most used medium of communication on the internet. Various social networks, customer
care websites and forums have used this technology to grow, enhance, and increase the efficiency and
productivity of their sites and products.

Implementing a web chat from scratch can be very tricky This project however show how simple a web chat
can be built from scratch using PHP and MySQL. This includes

1. A signup and login platform


2. A real time chat platform
3. Offline messaging and retrieval

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
2

The login section will have login facility for the admin and for the user who will operate this system. While
taking orders from its customers, it will take all the details of its customers who is placing the orders and all
the details for the recipient such as its address, name, mobile number. process system will generate a
tracking id for their products. Through this tracking id, customers or its recipient will able to track their
products from any location using internet. It will provide status of the product after placing orders within 1
minute.

This web chat system Project will provide information recipient with following details:- where the current
consignment is, till when it will reached its final destination, if any delay then reason of the delay, the route
of current consignment, date of placing consignment, final date to reach its destination.

When the consignment will visit to the city office of destination, a message will be send to the recipient with
delivery status confirmation. Then after getting this message its recipient can take its parcels by using their
Track Id. When its recipient will receive their parcels, then this Track Id will be deleted automatically from
the system database after 1 week by sending final confirmation message to its recipient mobile number
which will include information of Track Id, date of receiving and time along with greeting message for
providing further service in future.

In modern age, as time increase, needs & requirements of the person are also increased. They want more
facility & try to do their task quickly & within time. But they can not get all the things at nearest market or
area, so they have to import the things from any place in the world.

Within the country, the things can be imported through post service. But it consumes the time & sometimes
problem of damage or missing occur. Where as in the international market, the one way is shipping. But it
also requires more time.

The web chat is one of the solutions of these problems. It is used to send some things to any person in the
world within time.

The web chat has number of branches, which are spread over the country or the world. So that when person
wants to send things then he has to contact at nearest courier service branch. The courier company creates
the schedule & gives internal/external services. The courier service work as destination office or source
office. The source office branch receives the order means consignments & sends it to the destination courier
branch. The company has certain rules according to the weight.
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
WEB CHAT SYSTEM
3

Using the courier service person can easily send his/her parcel to other person in the particular destination
within the time. Now days, 50% of companies of the world uses the services of various courier company.

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
4

PROJECT DEFINITION

The main objective of the project on web chat is to manage the details of chat profile, chat user, group chat.
It manages all the information about chat profile, multi chat. The project totally build at administrative end
and thus only the administer is guaranteed the access. The purpose of the project is to build an application
program to reduce the manual work for managing the chat profile, chat user, multi chat, chat history. It
tracks all the details about the history, group chat.
Functionalities provided:
 It tracks all the information of chat user, multi chat.
 Provide searching facilities based on user profile.
 Manage information of chat user.
 Show the information and description of the chat profile, chat history.
 To increase efficiency of managing the chat profiles, chat user.
 Editing, adding records is improved which result in proper resources management of chat profiles
data.
 Manage information of group chat.

1.1 PURPOSE
It may help collecting perfect management in details. In a very short time, the collection will
be obvious, simple and sensible. It will help a person to know the management of passed
year perfectly and vividly. It also helps in current all works relative to web chat. It will be
also reduced the cost of collecting the management and collection procedure will go on
smoothly.
 Person has to fill only one form that can be easily generated.
 To assist the client in capturing the effort less medium.
 To satisfy user requirement.
 Be easy to understand to the user and operator
 Have a good user interface.
 Be expandable
 Delivered on schedule within the budget.

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
5

1.1.1 MODULE DESCRIPTION


 Login module: used for managing the login details.
 User/Register module: used for managing the user of the system.
 Group chat module: used for managing the group chat information.
 Chat history module: used for managing the information and details of chat user.
 Chat profile management module: used for managing the chat profile details.
 Smiles chat module: used for managing the details of smiles chat.

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
6

2. LITERATURE SURVEY

2.1 A. EXISTING SYSTEM


In existing system the chat are done only manually but in proposed system we have to computerize the
exams using this application.
 Chat only online

 No Data Security

 More man power

 Time consuming

 No direct role of higher officials

2.1. B. PROPOSED SYSTEM


The aim of proposed system is to develop a system of improved facilities. The proposed
system can overcome all the limitations of the existing system. The system provides proper
security and reduces the manual work..
 Minimize minimal data entry.
 Minimize time needed for the various processing.
 Chat in Local System connection so it is cheap.
 Better Communication.

 Secure and safe system.

 Flexible system you can edit its source code to make it more attractive or useful.

 Admin can keep track on whole chatting.

 We can share files also through this system.

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
7

2.2 FEASIBILITY STUDY


After doing the project web chat, study and analyzing all the existing or required functionalities of the
system, the next task is to do the feasibility study for the project. All projects are feasible- given unlimited
resources and infinite time.
Feasibility study includes consideration of all the possibilities ways to provide solution to the given problem.
The proposed solution should satisfy all the user requirements and should be flexible enough so that future
changes can be easily done based on the future upcoming requirements.

 economical feasibility
this is very important aspect to be considered while developing a project. We decided the
technology based on minimum possible cost factor. All hardware and software cost has to be
cheap.
Overall we have estimated that the benefits the organization is going to receive from the proposed
system will surely overcome the initial costs and the later on running cost for system.

 Technical feasibility
This included the study of function, performance and constraints that may affect the ability to
achieve an acceptable system. For this feasibility study, we studied complete functionality to be
provided in the system, as described in the system requirement specification, and checked if
everything was possible using different type of frontend and backend platform.

 operational feasibility
no doubt the proposed system is fully GUI based that is very user friendly and all inputs to be taken
all self-explanatory even to a layman. Besides, a proper training has been conducted to let know
the essence of the system to the users so that they can feel comfortable with new system. As far
our study is concerned the clients are comfortable and happy as the system has cut down their
loads and doing.

2.3 TECHNOLOGIES USED:

a. PHP (SERVER-SIDE SCRIPT )


DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
WEB CHAT SYSTEM
8

The most popular server-side language on the web, PHP is designed to pull and edit information in the
database. It’s most commonly bundled with databases written in the SQL language. PHP was designed
strictly for the web and remains one of the most widely used languages around. It’s easy to install and
deploy, is staying competitive with lots of modern frameworks, and is the foundation for a number of
content-management systems. PHP-powered sites: WordPress, Wikipedia, Facebook

 Runs on a server, embedded in the site’s code

 Designed to interact with back-end permanent storage, like databases, and process information from
the server to access the database—like a direct line from user to database

 Facilitates the transfer of data from server to browser, bringing pages to life in the browser, e.g.,
processing and then delivering a field that a user requests or submits in a form

 Runs on-call. When a webpage is “called up,” or when parts of pages are “posted back” to the server
with AJAX, server-side scripts process and return data

 Powers functions in dynamic web applications, such as user validation, saving and retrieving data,
and navigating between other pages

 Plays a big role in how a database is built from the ground up and managed afterwards—an example
of how roles often overlap in all aspects of development

 Build application programming interfaces (APIs), which control what data and software a site
shares with other apps

b. MYSQL:

its an open source relational database management system. It is based on the structure query language
(SQL), which is used for adding, removing, and modifying information in the database. Standard SQL
commands, such as ADD, DROP, INSERT, and UPDATE can be used with MySQL.

MySQL can be used for a variety of applications, but is most commonly found on Web servers. A website
that uses MySQL may include Web pages that access information from a database. These pages are often
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
WEB CHAT SYSTEM
9

referred to as "dynamic," meaning the content of each page is generated from a database as the page loads.
Websites that use dynamic Web pages are often referred to as database-driven websites.

Many database-driven websites that use MySQL also use a Web scripting language like PHP to access
information from the database. MySQL commands can be incorporated into the PHP code, allowing part or
all of a Web page to be generated from database information. Because both MySQL and PHP are both open
source (meaning they are free to download and use), the PHP/MySQL combination has become a popular
choice for database-driven websites.

 phpMyAdmin:
phpMyAdmin is a free and open source tool written in PHP intended to handle the administration of
MySQL with the use of a web browser. It can perform various tasks such as creating, modifying or deleting
databases, tables, fields or rows; executing SQL statements; or managing users and permissions. The
software, which is available in 78 languages is maintained by The phpMyAdmin Project.
It can import data from CSV and SQL, and transform stored data into any format using a set of predefined
functions, like displaying BLOB-data as images or download-links.

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
10

2.4. HARDWARE AND SOFTWARE REQUIREMENTS

2.4.1 SOFTWARE REQUIREMENTS:

Name Specification
Operating system Windows7, Linux
Language Php, mysql, javascript
Database Mysql
Browser Chrome
Web server Xampp

2.4.2 HARDWARE REQUIREMENTS:

Name of component Specification


Processor Intel i3 and above
Ram 4gb and above
Hard disk 20gb min required

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
11

3. SOFTWARE REQUIREMENT SPECIFICATION

The software requirements specification is produced at the culmination of the analysis task. The function and
performance allocated to software as part of system engineering are refined by establishing a complete
information description, a detailed functional and behavioural description, and indication of performance
requirements and design constraints, appropriate validation criteria, and other data pertinent to requirements.

The proposed system has the following requirements:


 System need store information about new entry of chat profile.
 System need to maintain quantity record.
 System need to keep the record of chat history.
 System need to update and delete the record
 It also needs a security system to prevent data.
 The users will be using the chat application and the stakeholders will develop, maintain, and test the
chat application.
 The users will be anyone who has the chat application and registers for it
 When the client runs the chat application, the client will see the main menu, which will welcome them,
At the main menu, the client will have the choice to register for the chat application, login to the chat
application, or exit it.
 The user must register in order to login, the user must login in order to send messages to those who are
online, and must be able to logout if the user wants to logout.
 After the client is logged in, the client can choose to send a message, only if another client is online,
check who is online, and be able to logout when the client wants to, which will be by logging out by
hitting the logout button or by hitting the exit button.
 When the client wants to see who is online, the client clicks the “who is online” button in the online
menu, and the client can choose who to message, by double clicking the name.
 When the client wants to message the user, the client clicks on the name, the user can send a message
to another online user. Some character limitations for typing might be put into place, only if it is
necessary.
 When the client wants to see the chat history, the user will be able to do so. The user will be able to
clear the history if the user wants to.

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
12

3.1 FUNCTIONAL REQUIREMENTS

This section will cover the functional requirements of the chat application.
 Login menu function
This functional requirement is for prompting the user with the option to register for the chat application,
logging in, or exit the program. It will take the form of a GUI

 Register function (Login Menu aspect)


This aspect of the login menu will ask the user for the name, username, and password of the client. It will
check if the username has been taken and will close if the username is not taken and will go back to the main
login menu.

 Login function (Login Menu aspect)


This aspect will ask for the username and password. Errors will occur if a space is left blank, the username
doesn’t exist, or the password doesn’t match with the username. If the username and password matches, you
are online and able to message anyone else online.

 Exit (Login Menu aspect)


This aspect will close the chat application.

 Online Menu function


This function will give the option of seeing who is online, the option of sending a message to whoever is
online, and the option to logout.

 Who is online (Online Menu aspect)


This aspect will show who is online and will give the user the ability to click on a user and send a message to
that user.

 Send a message (Online Menu Aspect)


This aspect will give the user the ability to send a message to whoever they want who is online and selected
by the user.

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
13

 Logout (Online Menu aspect)


This aspect will give the option to logout of the chat application and will go back to the login menu.

3.2 NON-FUNCTIONAL REQUIREMENTS


These are the non-functional requirements of the chat application. This is basically the section that deals
with the quality of the chat application rather than the functionalities of the application.

 User Friendly
The chat application needs to be user friendly, when using its user interface.

 GUI
By using GUI’s, it should make the application more user friendly and better to use instead of a command
line. Buttons will be used.

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
14

4. SYSTEM DESIGN AND ANALYSIS

4.1 SYSTEM DESIGN

in this phase, a logical system is built which fulfils the given requirements. Design phase of software
development deals with transforming the clients requirements into a logically working system. Normally,
design is performed in the following two steps:

 primary design phase:

In this phase, the system is designed at block level. The block are created on the basis of analysis done
in the problem identification phase. Different blocks are created for different functions emphasis is put
on minimising the information flow between blocks. Thus, all activities which require more interaction
are kept in on e block.

 Secondary design phase:


In the secondary phase the detailed design of every block is performed.

The general tasks involved in the design process are the following:

 Design various blocks for overall system process.


 Design smaller, compact and workable modules in each block.
 Design various database structures.
 Specify details of program to achieve desired functionality.
 Design the form of inputs, and outputs of the system.
 Perform documentation of the design.
 System reviews.

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
15

 User interface design:

User interface design is concerned with the dialogue between a user and the computer. It is concerned with
everything from starting the system or logging into the system to the eventually presentation of desired
outputs and inputs. The overall flow of screens and messages is called a dialogue.

The following steps are various guidelines for user interface design:
 The system user should always be aware of what to do next.
 The screen should be formatted so that various types of information, instructions and messages
always appears in the same general display area.\
 Messages, instruction or information should be displayed long enough to allow system user to read
them.
 User display attributes sparingly.
 Default values for fields and answers to be entered by the user should be specified.
 A user should not be allowed to proceed without correcting an error
 The system user should never get an operating system message or fatal error.

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
16

4.2 CONTENT DIAGRAM

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
17

5. DETAILED DESIGN

5.1 DATA FLOW DIAGRAM

a. Level 0:

b. Level 1:

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
18

c. Level 2:

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
19

5.2 USE CASE DIAGRAM:

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
20

5.3 ER DIAGRAM

5.4 SEQUENCE DIAGRAM

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
21

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
22

6. IMPLEMENTATION

6.1 IMPLEMENTATION CODE

Index.php:

<html>
<head>
<title>Welcome to WebChat</title>
<link rel="stylesheet" type="text/css" href="julio.css">
<script src="jquery-3.3.1.js"></script>
</head>
<body>
<form><header style="text-align:center; font-size:50px">webchat</header></form>
<div class="login">
<center>
<form method="post" action="login.php">
<h1 >sign in</h1>
<input type="text" name="uname" placeholder="user name" id="username"><br>
<input type="password" name="pass" placeholder="password" id="password"><br>
<button type="submit" name="submit" value="submit" style="background-color: #665851;
color: white;" >login</button>
<input type="button" id="mybtn" value="register">
<script>
var btn=document.getElementById('mybtn');
btn.addEventListener('click',function() {
document.location.href='register.php';
});
</script> </form> </div>
<div class="shadow"> </div> </center>
</body>
</html>
Register.php:

<html>
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
WEB CHAT SYSTEM
23

<head>
<title>register account</title>
<script src="jquery-3.3.1.js"></script>
<link rel="stylesheet" type="text/css" href="reg.css">
</head>
<body>
<form>
<header style="text-align:center; font-size:50px">Register</header>
</form>
<div class="login">
<form action="signup.php" method="post">
<h1>sign up</h1>
<input type="text" name="uname" placeholder="user name"><br>
<input type="text" name="email" placeholder="email address" ><br>
<input type="password" name="pass" placeholder="password"><br>
<button style="background-color: #665851; color: white;" type="submit">register</button>
<input type="button" id="mybtn1" value="back">
</form>
<script>
var btn=document.getElementById('mybtn1');
btn.addEventListener('click',function() {
document.location.href='index.php';
});
</script>
</div>
</body>
</html>

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
24

Login.php

<html>
<head> <script src="jquery-3.3.1.js"></script> </head>
<body>
<?php
if(isset($_POST['submit'])){
if (empty($_POST['uname']) || empty($_POST['pass'])) {
/* Username or Password is invalid */
echo "<script> alert('username and password is empty');
window.location.href='index.php';</script>";
//header("Location:index.php");
}
else{
session_start();
include "db.php";
$name=$_POST['uname'];
$pass=$_POST['pass'];
$query="select * from profile where name='$name' and pass='$pass'";
$result=mysqli_query($con,$query);
$nrow=mysqli_num_rows($result);
if($nrow > 0){
while($row=mysqli_fetch_assoc($result) > 0){
$_SESSION['name']=$_POST['uname'];
header("Location:home.php");
}
}else
header("Location:index.php");
}
}
?>
</body>
</html>

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
25

home.php

<?php
session_start();
include 'db.php';
require('func.php');
?>
<?php
if(isset($_POST['send'])){
if(sendmsg($_SESSION['name'],$_POST['msg']))
echo "message send";
else
echo "message not send";
}
?>
<html>
<head>
<title>send a message in group</title>
<link rel="stylesheet" type="text/css" href="home.css">
<script src="jquery-3.3.1.js"></script>
</script>
</head>
<body onload="rsend();">
<div style="width:100px; height: 30px; text-align: center; background-color: red; float: left">
<form action="logout.php">
<input type="submit" style="width:100; background-color: blue; color:white" value="logout">
</form>
</div>
<div style="width:100px; height: 30px; background-color: blue; align: center; float: left "> online</div>
<div style="width:100px; height: 30px; text-align: center; background-color: green; float:left">
<input id="photo-hide" type="file" name="image">
</div>
<br>
<h1>logged in as: <?php echo $_SESSION['name']; ?> </h1>
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
WEB CHAT SYSTEM
26

<div class="chatbox">
<div class="chatlogs">
<div class="chat">
<div id="chatmessage"></div>
</div>
<script type="text/javascript" src="jquery-3.3.1.js"></script>
<script type="text/javascript" src="autochat.js"></script>
</div>
<div class="chat-form">
<form action="home.php" name="form1" method="post">
<?php /* echo $_SESSION['name']; */ ?>
<textarea name="msg" placeholder="send message"class="form-control"></textarea>
<input id="test1" type="submit" name="send" value="send" >
</form>
</div>
</div>
</center>
</body>
</html>

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
27

Func.php

<?php
function getmsg(){
$db_host="localhost";
$db_user="root";
$db_pass="";
$db_name="group";
$connection=mysqli_connect($db_host,$db_user,$db_pass);
mysqli_select_db($connection,$db_name);
$query="SELECT `name`, `msg` FROM post order by id DESC";
$run=mysqli_query($connection,$query);
$messages=array();
while($message1=mysqli_fetch_assoc($run)){
$messages[]=array('Sender'=>$message1['name'],'Message'=>$message1['msg']); }
return $messages;
}
?>
<?php
function sendmsg(){
include 'db.php';
if($_POST['send']){
$msg=$_POST['msg'];
$name=$_SESSION['name'];
$query="insert into post(msg,name) values('$msg','$name')";
$result=mysqli_query($con,$query);
if($result)
return true;
else
return false;
}
else
return false;
} ?> <?php
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
WEB CHAT SYSTEM
28

/**
* @file
* The PHP page that serves all page requests on a Drupal installation.
*
* The routines here dispatch control to the appropriate handler, which then
* prints the appropriate page.
*
* All Drupal code is released under the GNU General Public License.
* See COPYRIGHT.txt and LICENSE.txt.
*/

/**
* Root directory of Drupal installation.
*/
define('DRUPAL_ROOT', getcwd());

require_once DRUPAL_ROOT . '/includes/bootstrap.inc';


drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
menu_execute_active_handler();

Code of Courier fetch:

<?php

/**
* @file

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
29

* The main autoassignrole.module file


*
* Designate a role to assign all new users to in addition to providing a
* mechanism for new users to select a role or role for their account.
*/

// Says to use element of type radio for role selection.


define('AUTOASSIGNROLE_ELEMENT_RADIO_CHECKBOX', 0);

// Says to use element of type select for role selection.


define('AUTOASSIGNROLE_ELEMENT_SELECT', 1);

// Sets the page display for standard.


define('AUTOASSIGNROLE_PAGE_DISPLAY_STANDARD', 0);

// Sets the page display for individual.


define('AUTOASSIGNROLE_PAGE_DISPLAY_INDIVIDUAL', 1);

/**
* Implements hook_permission().
*/
function autoassignrole_permission() {
return array(
'administer autoassignrole' => array(
'title' => t('Administer auto assign role'),
'description' => t('Perform administration tasks for auto assign role.'),
),

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
30

);
}

/**
* Implements hook_menu().
*/
function autoassignrole_menu() {
$items = array();
$items['admin/config/people/autoassignrole'] = array(
'title' => 'Auto assign role',
'description' => 'Configure auto role assignment.',
'access arguments' => array('administer autoassignrole'),
'page callback' => 'autoassignrole_admin_block_page',
'file' => 'autoassignrole.admin.inc',
);
$items['admin/config/people/autoassignrole/auto'] = array(
'title' => 'Automatic',
'description' => 'Configure which role(s) are automatically assigned on user creation.',
'access arguments' => array('administer autoassignrole'),
'page callback' => 'drupal_get_form',
'page arguments' => array('autoassignrole_auto_settings'),
'file' => 'autoassignrole.admin.inc',
);
$items['admin/config/people/autoassignrole/user'] = array(
'title' => 'User choice',
'description' => 'Configure the ability for an end user to choose their own roles during
registration.',

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
31

'access arguments' => array('administer autoassignrole'),


'page callback' => 'drupal_get_form',
'page arguments' => array('autoassignrole_user_settings'),
'file' => 'autoassignrole.admin.inc',
);
$items['admin/config/people/autoassignrole/pages'] = array(
'title' => 'Per Role Pages',
'description' => 'Configure individual pages to allow user to sign up for a particular role',
'access arguments' => array('administer autoassignrole'),
'page callback' => 'autoassignrole_list_pages',
'file' => 'autoassignrole.admin.inc',
);
$items['admin/config/people/autoassignrole/pages/add'] = array(
'title' => 'Add Auto Assign Role Page',
'access arguments' => array('administer autoassignrole'),
'page callback' => 'drupal_get_form',
'page arguments' => array('autoassignrole_page_form', 'add'),
'type' => MENU_LOCAL_ACTION,
'file' => 'autoassignrole.admin.inc',
);
$items['admin/config/people/autoassignrole/pages/edit/%'] = array(
'title' => 'Edit Auto Assign Role Page',
'access arguments' => array('administer autoassignrole'),
'page callback' => 'drupal_get_form',
'page arguments' => array('autoassignrole_page_form', 'edit', 6),
'file' => 'autoassignrole.admin.inc',
);

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
32

$items['admin/config/people/autoassignrole/pages/delete/%'] = array(
'title' => 'Delete Auto Assign Role Page',
'access arguments' => array('administer autoassignrole'),
'page callback' => 'drupal_get_form',
'page arguments' => array('autoassignrole_page_delete_confirm', 6),
'file' => 'autoassignrole.admin.inc',
);

$pages = autoassignrole_get_pages();
foreach ($pages as $page) {
$rids = unserialize($page->rids);
switch ($page->display) {
case AUTOASSIGNROLE_PAGE_DISPLAY_STANDARD:
$items[$page->path] = array(
'title' => check_plain($page->title),
'page arguments' => array($rids),
'page callback' => 'autoassignrole_register',
'access callback' => 'user_register_access',
'file' => 'autoassignrole.paths.inc',
'type' => MENU_NORMAL_ITEM,
'menu_name' => $page->menu,
);
$items[$page->path . '/register'] = array(
'title' => 'Register',
'page arguments' => array($rids),
'page callback' => 'autoassignrole_register',
'access callback' => 'user_register_access',

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
33

'file' => 'autoassignrole.paths.inc',


'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items[$page->path . '/login'] = array(
'title' => 'Log In',
'page callback' => 'autoassignrole_login',
'access callback' => 'user_is_anonymous',
'file' => 'autoassignrole.paths.inc',
'type' => MENU_LOCAL_TASK,
);
$items[$page->path . '/password'] = array(
'title' => 'Request New Password',
'page callback' => 'autoassignrole_password',
'access callback' => 'user_is_anonymous',
'file' => 'autoassignrole.paths.inc',
'type' => MENU_LOCAL_TASK,
);
break;

case AUTOASSIGNROLE_PAGE_DISPLAY_INDIVIDUAL:
$items[$page->path] = array(
'title' => check_plain($page->title),
'page arguments' => array($rids),
'page callback' => 'autoassignrole_register',
'access callback' => 'user_register_access',
'file' => 'autoassignrole.paths.inc',
'type' => MENU_CALLBACK,

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
34

);
$items[$page->path . '/register'] = array(
'title' => 'Register',
'page arguments' => array($rids),
'page callback' => 'autoassignrole_register',
'access callback' => 'user_register_access',
'file' => 'autoassignrole.paths.inc',
'type' => MENU_CALLBACK,
);
$items[$page->path . '/login'] = array(
'title' => 'Log In',
'page callback' => 'autoassignrole_login',
'access callback' => 'user_is_anonymous',
'file' => 'autoassignrole.paths.inc',
'type' => MENU_CALLBACK,
);
$items[$page->path . '/password'] = array(
'title' => 'Request New Password',
'page callback' => 'autoassignrole_password',
'access callback' => 'user_is_anonymous',
'file' => 'autoassignrole.paths.inc',
'type' => MENU_CALLBACK,
);
break;
}
}

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
35

return $items;
}

/**
* Finds any role ids attached to current page, if any.
*/
function autoassignrole_get_active_path_rid() {
$item = menu_get_item();
if ($item['page_callback'] == 'autoassignrole_register') {
return $item['page_arguments'][0];
}
return FALSE;
}

/**
* Implements hook_user_presave().
*/
function autoassignrole_user_presave(&$edit, $account, $category) {
// Use case http://drupal.org/node/971622
// Make sure we only assign roles automatically when enabled to do so.
if (variable_get('autoassignrole_auto_active', 0) ||
variable_get("autoassignrole_user_active", 0)
|| (variable_get('autoassignrole_admin_active', 0) && user_access('administer users'))
|| autoassignrole_get_active_path_rid()) {
// Use case http://drupal.org/node/944864
// Only assign roles if this is a new account.
if (isset($account->is_new) && !empty($account->is_new)) {

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
36

// Get the existing user roles with the exception of the anonymous role.
$user_roles = user_roles(TRUE);
$roles_to_add = array();

// Add in automatic roles.


if ((variable_get('autoassignrole_auto_active', 0) && !user_access('administer users'))
|| (variable_get('autoassignrole_admin_active', 0) && user_access('administer users')))
{
$roles_to_add += array_intersect_key($user_roles,
array_filter(variable_get('autoassignrole_auto_roles', array())));
}

// Add in user selected roles if any.


if (variable_get("autoassignrole_user_active", 0) && !empty($edit['user_roles'])) {
// Value is a single, convert to array.
if (!is_array($edit['user_roles'])) {
$edit['user_roles'] = array($edit['user_roles'] => $edit['user_roles']);
}
$roles_to_add += array_intersect_key($user_roles, array_filter($edit['user_roles']));
}

// Add page-specific roles.


$page_rids = autoassignrole_get_active_path_rid();
if ($page_rids) {
$roles_to_add = array_intersect_key($user_roles, array_filter($page_rids));
}

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
37

// Make sure the roles key exists.


if (!isset($edit['roles'])) {
$edit['roles'] = array();
}

// Add in the new roles to override the current roles.


$edit['roles'] = $roles_to_add + $edit['roles'];
}
}
}

/**
* Implements hook_form_FORM_ID_alter() for user_register_form().
*/
function autoassignrole_form_user_register_form_alter(&$form, &$form_state) {
if (variable_get("autoassignrole_user_active", 0) && !user_access('administer users')
&& !autoassignrole_get_active_path_rid()) {

// Get a list of valid roles that can be selected.


$roles = array_intersect_key(user_roles(TRUE),
array_filter(variable_get('autoassignrole_user_roles', array())));

if ($roles) {
$form['autoassignrole_user'] = array(
'#type' => 'fieldset',
'#title' => filter_xss(variable_get('autoassignrole_user_fieldset_title', t('User Roles'))),
'#collapsible' => FALSE,

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
38

'#collapsed' => FALSE,


);

// Sort the roles.


if (variable_get('autoassignrole_user_sort', 'SORT_ASC') == 'SORT_ASC') {
asort($roles);
}
elseif (variable_get('autoassignrole_user_sort', 'SORT_DESC') == 'SORT_DESC') {
arsort($roles);
}
else {
drupal_sort_weight($roles, $roles);
}

$multiple = variable_get('autoassignrole_user_multiple', 0);


$user_selection = variable_get('autoassignrole_user_selection',
AUTOASSIGNROLE_ELEMENT_RADIO_CHECKBOX);

$type = 'select';
if ($user_selection == AUTOASSIGNROLE_ELEMENT_RADIO_CHECKBOX) {
$type = $user_selection == AUTOASSIGNROLE_ELEMENT_RADIO_CHECKBOX && !
$multiple ? 'radios' : 'checkboxes';
}

// If not multiple + not required + select box, need a none selection.


if (!$multiple && !variable_get('autoassignrole_user_required', 0) && $type == 'select') {
$roles = array(0 => t('None')) + $roles;

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
39

// Add in the element.


$form['autoassignrole_user']['user_roles'] = array(
'#type' => $type,
'#title' => filter_xss(variable_get('autoassignrole_user_title', t('Role'))),
'#options' => $roles,
'#description' => filter_xss(variable_get('autoassignrole_user_description', t('Select a
role'))),
'#required' => variable_get('autoassignrole_user_required', 0),
'#multiple' => $multiple,
);
}
}
}

/**
* Function to retrieve all role-specific pages.
*
* @return SelectQuery
* An array of page objects.
*/
function autoassignrole_get_pages() {
$query = _autoasignrole_get_page_query();
return $query->execute();
}

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
40

/**
* Function to get role-specific page details.
*
* @param int $id
* The id of the page to be updated.
*
* @return SelectQuery
* A query object with all page details.
*/
function autoassignrole_get_page($id) {
$query = _autoasignrole_get_page_query();
$query->condition('rid_page_id', $id, '=');
return $query->execute()->fetchObject();
}

/**
* Helper method for getting the page query object.
*
* @return SelectQuery
* The query object.
*/
function _autoasignrole_get_page_query() {
return db_select('autoassignrole_page', 'p')
->fields('p', array(
'rids',
'path',
'title',

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
41

'menu',
'display',
));
}

Code of Role Assignment:


<?php

/**
* @file
* Paths used for autoassignrole created user pages.
*
* Autoassignrole allows an admin to create specific register, login and reset
* password pages for a particular set of roles. The menu callback arguments
* for these pages are defined here.
*
* These functions simply call the standard user forms from Drupal core, the
* reason we wrap them like this is so that we can detect when one of our
* role-specific pages are being called rather than the default ones.
*/

//We require this file from the user module to get the user_pass form.
require_once drupal_get_path('module', 'user') . '/user.pages.inc';

/**
* Loads the user registration form.
*

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
42

* $rid is not actually used in the function but by passing it we can find out
* which roles are meant to be added to the new user by using
* autoassignrole_get_active_path_rid();
*
* @see autoassignrole.module
*
* @param $rid
* $rid is the 'rid_page_id' of the page we are currently generating.
*
* @return string
* User registration form renderer.
*/
function autoassignrole_register($rid) {
$output = drupal_get_form('user_register_form');
return $output;
}

/**
* Loads the user login form
*/
function autoassignrole_login() {
$output = drupal_get_form('user_login');
return $output;
}

/**
* Loads the password reset form

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
43

*/
function autoassignrole_password() {
$output = drupal_get_form('user_pass');
return $output;
}

Code of Node Save Redirect:


<?php

/**
* Implements hook_form_alter().
*
* Adds the action and redirect fields. Used by node type edit and node edit forms.
*/
function node_save_redirect_form_alter(&$form, &$form_state, $form_id) {

if (isset($form['#node_type'])) {

// ADdd the new radios buttons to the submission vertical tab.


$form['submission']['node_save_redirect'] = array(
'#type' => 'radios',
'#title' => t('Redirect after content creation'),
'#options' => array(0 => t('Default'),
1 => t('Return to Edit page after saving.'),
2 => t('Return to Content Overview after saving.'),
4 => t('Re-direct to My Workbench after saving'),
3 => t('Re-direct to another location')),

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
44

'#description' => t('Choose where the user should be sent after creating new content.'),
'#default_value' => variable_get('node_save_redirect_' . $form['#node_type']->type, 0)
);

// Add a textfield to the submission vertical tab.


$form['submission']['node_save_redirect_location'] = array(
'#type' => 'textfield',
'#title' => 'Custom Redirect Location',
'#default_value' => variable_get('node_save_redirect_location_' . $form['#node_type']-
>type, ''),
'#states' => array(
'visible' => array(
':input[name="node_save_redirect"]' => array('value' => '3'),
),
)
);
}

// Add a new submit function.


if (strstr($form_id, '_node_form')) {
$form['actions']['submit']['#submit'][] = 'node_save_redirect_submit';
}
}

/**
* A function that is called when a node is saved.
*

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
45

* @param array $form


* @param array $form_state
*/
function node_save_redirect_submit($form, &$form_state) {

// load settings
$node_save_redirect_settings = variable_get('node_save_redirect_' . $form['type']
['#value'], NULL);
$custom_location = variable_get('node_save_redirect_location_' . $form['type']['#value'],
'');

if (!is_null($node_save_redirect_settings)) {

// A destination in $_GET always overrides the function arguments. @see drupal_goto


unset($_GET['destination']);

if ($node_save_redirect_settings == '1') {
$form_state['redirect'] = 'node/' . $form_state['nid'] . '/edit';
}
else if ($node_save_redirect_settings == '2' && user_access('access content overview')) {
$form_state['redirect'] = 'admin/content';
}
else if ($node_save_redirect_settings == '4' && user_access('access workbench')) {
$form_state['redirect'] = 'admin/workbench';
}
else if ($node_save_redirect_settings == '3') {
$options = drupal_parse_url($custom_location);

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
46

$form_state['redirect'] = array($options['path'], array(


'query' => $options['query'],
'fragment' => $options['fragment']
));
}
}
}

Code for Manage Couriers using ctools:


<?php

/**
* @file
* CTools primary module file.
*
* Most of the CTools tools are in their own .inc files. This contains
* nothing more than a few convenience functions and some hooks that
* must be implemented in the module file.
*/

define('CTOOLS_API_VERSION', '2.0.8');

/**
* The current working ctools version.
*
* In a release, it should be 7.x-1.x, which should match what drush make will
* create. In a dev format, it should be 7.x-1.(x+1)-dev, which will allow

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
47

* modules depending on new features in ctools to depend on ctools > 7.x-1.x.


*
* To define a specific version of CTools as a dependency for another module,
* simply include a dependency line in that module's info file, e.g.:
* ; Requires CTools v7.x-1.4 or newer.
* dependencies[] = ctools (>=1.4)
*/
define('CTOOLS_MODULE_VERSION', '7.x-1.6');

/**
* Test the CTools API version.
*
* This function can always be used to safely test if CTools has the minimum
* API version that your module can use. It can also try to protect you from
* running if the CTools API version is too new, but if you do that you need
* to be very quick about watching CTools API releases and release new versions
* of your software as soon as the new release is made, or people might end up
* updating CTools and having your module shut down without any recourse.
*
* It is recommended that every hook of your module that might use CTools or
* might lead to a use of CTools be guarded like this:
*
* @code
* if (!module_invoke('ctools', 'api_version', '1.0')) {
* return;
*}
* @endcode

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
48

*
* Note that some hooks such as _menu() or _theme() must return an array().
*
* You can use it in your hook_requirements to report this error condition
* like this:
*
* @code
* define('MODULENAME_MINIMUM_CTOOLS_API_VERSION', '1.0');
* define('MODULENAME_MAXIMUM_CTOOLS_API_VERSION', '1.1');
*
* function MODULENAME_requirements($phase) {
* $requirements = array();
* if (!module_invoke('ctools', 'api_version',
MODULENAME_MINIMUM_CTOOLS_API_VERSION,
MODULENAME_MAXIMUM_CTOOLS_API_VERSION)) {
* $requirements['MODULENAME_ctools'] = array(
* 'title' => $t('MODULENAME required Chaos Tool Suite (CTools) API Version'),
* 'value' => t('Between @a and @b', array('@a' =>
MODULENAME_MINIMUM_CTOOLS_API_VERSION, '@b' =>
MODULENAME_MAXIMUM_CTOOLS_API_VERSION)),
* 'severity' => REQUIREMENT_ERROR,
* );
* }
* return $requirements;
*}
* @endcode
*

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
49

* Please note that the version is a string, not an floating point number.
* This will matter once CTools reaches version 1.10.
*
* A CTools API changes history will be kept in API.txt. Not every new
* version of CTools will necessarily update the API version.
* @param $minimum
* The minimum version of CTools necessary for your software to run with it.
* @param $maximum
* The maximum version of CTools allowed for your software to run with it.
*/
function ctools_api_version($minimum, $maximum = NULL) {
if (version_compare(CTOOLS_API_VERSION, $minimum, '<')) {
return FALSE;
}

if (isset($maximum) && version_compare(CTOOLS_API_VERSION, $maximum, '>')) {


return FALSE;
}

return TRUE;
}

// -----------------------------------------------------------------------
// General utility functions

/**
* Include .inc files as necessary.

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
50

*
* This fuction is helpful for including .inc files for your module. The
* general case is including ctools funcitonality like this:
*
* @code
* ctools_include('plugins');
* @endcode
*
* Similar funcitonality can be used for other modules by providing the $module
* and $dir arguments like this:
*
* @code
* // include mymodule/includes/import.inc
* ctools_include('import', 'mymodule');
* // include mymodule/plugins/foobar.inc
* ctools_include('foobar', 'mymodule', 'plugins');
* @endcode
*
* @param $file
* The base file name to be included.
* @param $module
* Optional module containing the include.
* @param $dir
* Optional subdirectory containing the include file.
*/
function ctools_include($file, $module = 'ctools', $dir = 'includes') {
static $used = array();

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
51

$dir = '/' . ($dir ? $dir . '/' : '');

if (!isset($used[$module][$dir][$file])) {
require_once DRUPAL_ROOT . '/' . drupal_get_path('module', $module) . "$dir$file.inc";
$used[$module][$dir][$file] = TRUE;
}
}

/**
* Include .inc files in a form context.
*
* This is a variant of ctools_include that will save information in the
* the form_state so that cached forms will properly include things.
*/
function ctools_form_include(&$form_state, $file, $module = 'ctools', $dir = 'includes') {
if (!isset($form_state['build_info']['args'])) {
$form_state['build_info']['args'] = array();
}

$dir = '/' . ($dir ? $dir . '/' : '');


form_load_include($form_state, 'inc', $module, $dir . $file);
}

/**
* Add an arbitrary path to the $form_state so it can work with form cache.
*

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
52

* module_load_include uses an unfortunately annoying syntax to work, making it


* difficult to translate the more simple $path + $file syntax.
*/
function ctools_form_include_file(&$form_state, $filename) {
if (!isset($form_state['build_info']['args'])) {
$form_state['build_info']['args'] = array();
}

// Now add this to the build info files so that AJAX requests will know to load it.
$form_state['build_info']['files']["$filename"] = $filename;
require_once DRUPAL_ROOT . '/' . $filename;
}

/**
* Provide the proper path to an image as necessary.
*
* This helper function is used by ctools but can also be used in other
* modules in the same way as explained in the comments of ctools_include.
*
* @param $image
* The base file name (with extension) of the image to be included.
* @param $module
* Optional module containing the include.
* @param $dir
* Optional subdirectory containing the include file.
*/
function ctools_image_path($image, $module = 'ctools', $dir = 'images') {

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
53

return drupal_get_path('module', $module) . "/$dir/" . $image;


}

/**
* Include css files as necessary.
*
* This helper function is used by ctools but can also be used in other
* modules in the same way as explained in the comments of ctools_include.
*
* @param $file
* The base file name to be included.
* @param $module
* Optional module containing the include.
* @param $dir
* Optional subdirectory containing the include file.
*/
function ctools_add_css($file, $module = 'ctools', $dir = 'css') {
drupal_add_css(drupal_get_path('module', $module) . "/$dir/$file.css");
}

/**
* Format a css file name for use with $form['#attached']['css'].
*
* This helper function is used by ctools but can also be used in other
* modules in the same way as explained in the comments of ctools_include.
*
* @code

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
54

* $form['#attached']['css'] = array(ctools_attach_css('collapsible-div'));
* $form['#attached']['css'][ctools_attach_css('collapsible-div')] = array('preprocess' =>
FALSE);
* @endcode
*
* @param $file
* The base file name to be included.
* @param $module
* Optional module containing the include.
* @param $dir
* Optional subdirectory containing the include file.
*/
function ctools_attach_css($file, $module = 'ctools', $dir = 'css') {
return drupal_get_path('module', $module) . "/$dir/$file.css";
}

/**
* Include js files as necessary.
*
* This helper function is used by ctools but can also be used in other
* modules in the same way as explained in the comments of ctools_include.
*
* @param $file
* The base file name to be included.
* @param $module
* Optional module containing the include.
* @param $dir

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
55

* Optional subdirectory containing the include file.


*/
function ctools_add_js($file, $module = 'ctools', $dir = 'js') {
drupal_add_js(drupal_get_path('module', $module) . "/$dir/$file.js");
}

/**
* Format a javascript file name for use with $form['#attached']['js'].
*
* This helper function is used by ctools but can also be used in other
* modules in the same way as explained in the comments of ctools_include.
*
* @code
* $form['#attached']['js'] = array(ctools_attach_js('auto-submit'));
* @endcode
*
* @param $file
* The base file name to be included.
* @param $module
* Optional module containing the include.
* @param $dir
* Optional subdirectory containing the include file.
*/
function ctools_attach_js($file, $module = 'ctools', $dir = 'js') {
return drupal_get_path('module', $module) . "/$dir/$file.js";
}

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
56

/**
* Get a list of roles in the system.
*
* @return
* An array of role names keyed by role ID.
*
* @deprecated
* user_roles() should be used instead.
*/
function ctools_get_roles() {
return user_roles();
}

/*
* Break x,y,z and x+y+z into an array. Numeric only.
*
* @param $str
* The string to parse.
*
* @return $object
* An object containing
* - operator: Either 'and' or 'or'
* - value: An array of numeric values.
*/
function ctools_break_phrase($str) {
$object = new stdClass();

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
57

if (preg_match('/^([0-9]+[+ ])+[0-9]+$/', $str)) {


// The '+' character in a query string may be parsed as ' '.
$object->operator = 'or';
$object->value = preg_split('/[+ ]/', $str);
}
else if (preg_match('/^([0-9]+,)*[0-9]+$/', $str)) {
$object->operator = 'and';
$object->value = explode(',', $str);
}

// Keep an 'error' value if invalid strings were given.


if (!empty($str) && (empty($object->value) || !is_array($object->value))) {
$object->value = array(-1);
$object->invalid_input = TRUE;
return $object;
}

if (empty($object->value)) {
$object->value = array();
}

// Doubly ensure that all values are numeric only.


foreach ($object->value as $id => $value) {
$object->value[$id] = intval($value);
}

return $object;

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
58

/**
* Set a token/value pair to be replaced later in the request, specifically in
* ctools_page_token_processing().
*
* @param $token
* The token to be replaced later, during page rendering. This should
* ideally be a string inside of an HTML comment, so that if there is
* no replacement, the token will not render on the page.
* @param $type
* The type of the token. Can be either 'variable', which will pull data
* directly from the page variables
* @param $argument
* If $type == 'variable' then argument should be the key to fetch from
* the $variables. If $type == 'callback' then it should either be the
* callback, or an array that will be sent to call_user_func_array().
*
* @return
* A array of token/variable names to be replaced.
*/
function ctools_set_page_token($token = NULL, $type = NULL, $argument = NULL) {
static $tokens = array();

if (isset($token)) {
$tokens[$token] = array($type, $argument);
}

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
59

return $tokens;
}

/**
* Easily set a token from the page variables.
*
* This function can be used like this:
* $token = ctools_set_variable_token('tabs');
*
* $token will then be a simple replacement for the 'tabs' about of the
* variables available in the page template.
*/
function ctools_set_variable_token($token) {
$string = '<!-- ctools-page-' . $token . ' -->';
ctools_set_page_token($string, 'variable', $token);
return $string;
}

/**
* Easily set a token from the page variables.
*
* This function can be used like this:
* $token = ctools_set_variable_token('id', 'mymodule_myfunction');
*/
function ctools_set_callback_token($token, $callback) {
// If the callback uses arguments they are considered in the token.
if (is_array($callback)) {

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
60

$token .= '-' . md5(serialize($callback));


}
$string = '<!-- ctools-page-' . $token . ' -->';
ctools_set_page_token($string, 'callback', $callback);
return $string;
}

/**
* Tell CTools that sidebar blocks should not be rendered.
*
* It is often desirable to not display sidebars when rendering a page,
* particularly when using Panels. This informs CTools to alter out any
* sidebar regions during block render.
*/
function ctools_set_no_blocks($blocks = FALSE) {
$status = &drupal_static(__FUNCTION__, TRUE);
$status = $blocks;
}

/**
* Wrapper function to create UUIDs via ctools, falls back on UUID module
* if it is enabled. This code is a copy of uuid.inc from the uuid module.
* @see http://php.net/uniqid#65879
*/

function ctools_uuid_generate() {
if (!module_exists('uuid')) {

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
61

ctools_include('uuid');

$callback = drupal_static(__FUNCTION__);

if (empty($callback)) {
if (function_exists('uuid_create') && !function_exists('uuid_make')) {
$callback = '_ctools_uuid_generate_pecl';
}
elseif (function_exists('com_create_guid')) {
$callback = '_ctools_uuid_generate_com';
}
else {
$callback = '_ctools_uuid_generate_php';
}
}
return $callback();
}
else {
return uuid_generate();
}
}

/**
* Check that a string appears to be in the format of a UUID.
* @see http://drupal.org/project/uuid
*
* @param $uuid

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
62

* The string to test.


*
* @return
* TRUE if the string is well formed.
*/
function ctools_uuid_is_valid($uuid = '') {
if (empty($uuid)) {
return FALSE;
}
if (function_exists('uuid_is_valid') || module_exists('uuid')) {
return uuid_is_valid($uuid);
}
else {
ctools_include('uuid');
return uuid_is_valid($uuid);
}
}

/**
* Add an array of classes to the body.
*
* @param mixed $classes
* A string or an array of class strings to add.
* @param string $hook
* The theme hook to add the class to. The default is 'html' which will
* affect the body tag.
*/

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
63

function ctools_class_add($classes, $hook = 'html') {


if (!is_array($classes)) {
$classes = array($classes);
}

$static = &drupal_static('ctools_process_classes', array());


if (!isset($static[$hook]['add'])) {
$static[$hook]['add'] = array();
}
foreach ($classes as $class) {
$static[$hook]['add'][] = $class;
}
}

/**
* Remove an array of classes from the body.
*
* @param mixed $classes
* A string or an array of class strings to remove.
* @param string $hook
* The theme hook to remove the class from. The default is 'html' which will
* affect the body tag.
*/
function ctools_class_remove($classes, $hook = 'html') {
if (!is_array($classes)) {
$classes = array($classes);
}

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
64

$static = &drupal_static('ctools_process_classes', array());


if (!isset($static[$hook]['remove'])) {
$static[$hook]['remove'] = array();
}
foreach ($classes as $class) {
$static[$hook]['remove'][] = $class;
}
}

// -----------------------------------------------------------------------
// Drupal core hooks

/**
* Implement hook_init to keep our global CSS at the ready.
*/
function ctools_init() {
ctools_add_css('ctools');
// If we are sure that CTools' AJAX is in use, change the error handling.
if (!empty($_REQUEST['ctools_ajax'])) {
ini_set('display_errors', 0);
register_shutdown_function('ctools_shutdown_handler');
}

// Clear plugin cache on the module page submit.


if ($_GET['q'] == 'admin/modules/list/confirm' && !empty($_POST)) {
cache_clear_all('ctools_plugin_files:', 'cache', TRUE);

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
65

}
}

/**
* Shutdown handler used during ajax operations to help catch fatal errors.
*/
function ctools_shutdown_handler() {
if (function_exists('error_get_last') AND ($error = error_get_last())) {
switch ($error['type']) {
case E_ERROR:
case E_CORE_ERROR:
case E_COMPILE_ERROR:
case E_USER_ERROR:
// Do this manually because including files here is dangerous.
$commands = array(
array(
'command' => 'alert',
'title' => t('Error'),
'text' => t('Unable to complete operation. Fatal error in @file on line @line:
@message', array(
'@file' => $error['file'],
'@line' => $error['line'],
'@message' => $error['message'],
)),
),
);

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
66

// Change the status code so that the client will read the AJAX returned.
header('HTTP/1.1 200 OK');
drupal_json($commands);
}
}
}

/**
* Implements hook_theme().
*/
function ctools_theme() {
ctools_include('utility');
$items = array();
ctools_passthrough('ctools', 'theme', $items);
return $items;
}

/**
* Implements hook_menu().
*/
function ctools_menu() {
ctools_include('utility');
$items = array();
ctools_passthrough('ctools', 'menu', $items);
return $items;
}

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
67

/**
* Implements hook_permission().
*/
function ctools_permission() {
return array(
'use ctools import' => array(
'title' => t('Use CTools importer'),
'description' => t('The import functionality allows users to execute arbitrary PHP code, so
extreme caution must be taken.'),
'restrict access' => TRUE,
),
);
}

/**
* Implementation of hook_cron. Clean up old caches.
*/
function ctools_cron() {
ctools_include('utility');
$items = array();
ctools_passthrough('ctools', 'cron', $items);
}

/**
* Implements hook_flush_caches().
*/
function ctools_flush_caches() {

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
68

// Only return the CSS cache bin if it has been activated, to avoid
// drupal_flush_all_caches() from trying to truncate a non-existing table.
return variable_get('cache_class_cache_ctools_css', FALSE) ? array('cache_ctools_css') :
array();
}

/**
* Implements hook_element_info_alter().
*
*/
function ctools_element_info_alter(&$type) {
ctools_include('dependent');
ctools_dependent_element_info_alter($type);
}

/**
* Implementation of hook_file_download()
*
* When using the private file system, we have to let Drupal know it's ok to
* download CSS and image files from our temporary directory.
*/
function ctools_file_download($filepath) {
if (strpos($filepath, 'ctools') === 0) {
$mime = file_get_mimetype($filepath);
// For safety's sake, we allow only text and images.
if (strpos($mime, 'text') === 0 || strpos($mime, 'image') === 0) {
return array('Content-type:' . $mime);

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
69

}
}
}

/**
* Implements hook_registry_files_alter().
*
* Alter the registry of files to automagically include all classes in
* class-based plugins.
*/
function ctools_registry_files_alter(&$files, $indexed_modules) {
ctools_include('registry');
return _ctools_registry_files_alter($files, $indexed_modules);
}

// -----------------------------------------------------------------------
// CTools hook implementations.

/**
* Implementation of hook_ctools_plugin_directory() to let the system know
* where all our own plugins are.
*/
function ctools_ctools_plugin_directory($owner, $plugin_type) {
if ($owner == 'ctools') {
return 'plugins/' . $plugin_type;
}
}

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
70

/**
* Implements hook_ctools_plugin_type().
*/
function ctools_ctools_plugin_type() {
ctools_include('utility');
$items = array();
// Add all the plugins that have their own declaration space elsewhere.
ctools_passthrough('ctools', 'plugin-type', $items);

return $items;
}

// -----------------------------------------------------------------------
// Drupal theme preprocess hooks that must be in the .module file.

/**
* A theme preprocess function to automatically allow panels-based node
* templates based upon input when the panel was configured.
*/
function ctools_preprocess_node(&$vars) {
// The 'ctools_template_identifier' attribute of the node is added when the pane is
// rendered.
if (!empty($vars['node']->ctools_template_identifier)) {
$vars['ctools_template_identifier'] = check_plain($vars['node']-
>ctools_template_identifier);
$vars['theme_hook_suggestions'][] = 'node__panel__' . check_plain($vars['node']-

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
71

>ctools_template_identifier);
}
}

/**
* Implements hook_page_alter().
*
* Last ditch attempt to remove sidebar regions if the "no blocks"
* functionality has been activated.
*
* @see ctools_block_list_alter().
*/
function ctools_page_alter(&$page) {
$check = drupal_static('ctools_set_no_blocks', TRUE);
if (!$check) {
foreach ($page as $region_id => $region) {
// @todo -- possibly we can set configuration for this so that users can
// specify which blocks will not get rendered.
if (strpos($region_id, 'sidebar') !== FALSE) {
unset($page[$region_id]);
}
}
}
$page['#post_render'][] = 'ctools_page_token_processing';
}

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
72

/**
* A theme post_render callback to allow content type plugins to use page
* template variables which are not yet available when the content type is
* rendered.
*/
function ctools_page_token_processing($children, $elements) {
$tokens = ctools_set_page_token();
if (!empty($tokens)) {
foreach ($tokens as $token => $key) {
list($type, $argument) = $key;
switch ($type) {
case 'variable':
$tokens[$token] = isset($elements[$argument]) ? $elements[$argument] : '';
break;
case 'callback':
if (is_string($argument) && function_exists($argument)) {
$tokens[$token] = $argument($elements);
}
if (is_array($argument) && function_exists($argument[0])) {
$function = array_shift($argument);
$argument = array_merge(array(&$elements), $argument);
$tokens[$token] = call_user_func_array($function, $argument);
}
break;
}
}
$children = strtr($children, $tokens);

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
73

}
return $children;
}

/**
* Implements hook_process().
*
* Add and remove CSS classes from the variables array. We use process so that
* we alter anything added in the preprocess hooks.
*/
function ctools_process(&$variables, $hook) {
if (!isset($variables['classes'])) {
return;
}

$classes = drupal_static('ctools_process_classes', array());

// Process the classses to add.


if (!empty($classes[$hook]['add'])) {
$add_classes = array_map('drupal_clean_css_identifier', $classes[$hook]['add']);
$variables['classes_array'] = array_unique(array_merge($variables['classes_array'],
$add_classes));
}

// Process the classes to remove.


if (!empty($classes[$hook]['remove'])) {
$remove_classes = array_map('drupal_clean_css_identifier', $classes[$hook]['remove']);

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
74

$variables['classes_array'] = array_diff($variables['classes_array'], $remove_classes);


}

// Since this runs after template_process(), we need to re-implode the


// classes array.
$variables['classes'] = implode(' ', $variables['classes_array']);
}

// -----------------------------------------------------------------------
// Menu callbacks that must be in the .module file.

/**
* Determine if the current user has access via a plugin.
*
* This function is meant to be embedded in the Drupal menu system, and
* therefore is in the .module file since sub files can't be loaded, and
* takes arguments a little bit more haphazardly than ctools_access().
*
* @param $access
* An access control array which contains the following information:
* - 'logic': and or or. Whether all tests must pass or one must pass.
* - 'plugins': An array of access plugins. Each contains:
* - - 'name': The name of the plugin
* - - 'settings': The settings from the plugin UI.
* - - 'context': Which context to use.
* @param ...
* zero or more context arguments generated from argument plugins. These

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
75

* contexts must have an 'id' attached to them so that they can be


* properly associated. The argument plugin system should set this, but
* if the context is coming from elsewhere it will need to be set manually.
*
* @return
* TRUE if access is granted, false if otherwise.
*/
function ctools_access_menu($access) {
// Short circuit everything if there are no access tests.
if (empty($access['plugins'])) {
return TRUE;
}

$contexts = array();
foreach (func_get_args() as $arg) {
if (is_object($arg) && get_class($arg) == 'ctools_context') {
$contexts[$arg->id] = $arg;
}
}

ctools_include('context');
return ctools_access($access, $contexts);
}

/**
* Determine if the current user has access via checks to multiple different
* permissions.

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
76

*
* This function is a thin wrapper around user_access that allows multiple
* permissions to be easily designated for use on, for example, a menu callback.
*
* @param ...
* An indexed array of zero or more permission strings to be checked by
* user_access().
*
* @return
* Iff all checks pass will this function return TRUE. If an invalid argument
* is passed (e.g., not a string), this function errs on the safe said and
* returns FALSE.
*/
function ctools_access_multiperm() {
foreach (func_get_args() as $arg) {
if (!is_string($arg) || !user_access($arg)) {
return FALSE;
}
}
return TRUE;
}

/**
* Check to see if the incoming menu item is js capable or not.
*
* This can be used as %ctools_js as part of a path in hook menu. CTools
* ajax functions will automatically change the phrase 'nojs' to 'ajax'

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
77

* when it attaches ajax to a link. This can be used to autodetect if


* that happened.
*/
function ctools_js_load($js) {
if ($js == 'ajax') {
return TRUE;
}
return 0;
}

/**
* Provides the default value for %ctools_js.
*
* This allows drupal_valid_path() to work with %ctools_js.
*/
function ctools_js_to_arg($arg) {
return empty($arg) || $arg == '%' ? 'nojs' : $arg;
}

/**
* Menu _load hook.
*
* This function will be called to load an object as a replacement for
* %ctools_export_ui in menu paths.
*/
function ctools_export_ui_load($item_name, $plugin_name) {
$return = &drupal_static(__FUNCTION__, FALSE);

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
78

if (!$return) {
ctools_include('export-ui');
$plugin = ctools_get_export_ui($plugin_name);
$handler = ctools_export_ui_get_handler($plugin);

if ($handler) {
return $handler->load_item($item_name);
}
}

return $return;
}

// -----------------------------------------------------------------------
// Caching callbacks on behalf of export-ui.

/**
* Menu access callback for various tasks of export-ui.
*/
function ctools_export_ui_task_access($plugin_name, $op, $item = NULL) {
ctools_include('export-ui');
$plugin = ctools_get_export_ui($plugin_name);
$handler = ctools_export_ui_get_handler($plugin);

if ($handler) {
return $handler->access($op, $item);

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
79

// Deny access if the handler cannot be found.


return FALSE;
}

/**
* Callback for access control ajax form on behalf of export ui.
*
* Returns the cached access config and contexts used.
* Note that this is assuming that access will be in $item->access -- if it
* is not, an export UI plugin will have to make its own callbacks.
*/
function ctools_export_ui_ctools_access_get($argument) {
ctools_include('export-ui');
list($plugin_name, $key) = explode(':', $argument, 2);

$plugin = ctools_get_export_ui($plugin_name);
$handler = ctools_export_ui_get_handler($plugin);

if ($handler) {
ctools_include('context');
$item = $handler->edit_cache_get($key);
if (!$item) {
$item = ctools_export_crud_load($handler->plugin['schema'], $key);
}

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
80

$contexts = ctools_context_load_contexts($item);
return array($item->access, $contexts);
}
}

/**
* Callback for access control ajax form on behalf of export ui
*
* Returns the cached access config and contexts used.
* Note that this is assuming that access will be in $item->access -- if it
* is not, an export UI plugin will have to make its own callbacks.
*/
function ctools_export_ui_ctools_access_set($argument, $access) {
ctools_include('export-ui');
list($plugin_name, $key) = explode(':', $argument, 2);

$plugin = ctools_get_export_ui($plugin_name);
$handler = ctools_export_ui_get_handler($plugin);

if ($handler) {
ctools_include('context');
$item = $handler->edit_cache_get($key);
if (!$item) {
$item = ctools_export_crud_load($handler->plugin['schema'], $key);
}
$item->access = $access;
return $handler->edit_cache_set_key($item, $key);

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
81

}
}

/**
* Implements hook_menu_local_tasks_alter().
*/
function ctools_menu_local_tasks_alter(&$data, $router_item, $root_path) {
ctools_include('menu');
_ctools_menu_add_dynamic_items($data, $router_item, $root_path);
}

/**
* Implement hook_block_list_alter() to potentially remove blocks.
*
* This exists in order to replicate Drupal 6's "no blocks" functionality.
*/
function ctools_block_list_alter(&$blocks) {
$check = drupal_static('ctools_set_no_blocks', TRUE);
if (!$check) {
foreach ($blocks as $block_id => $block) {
// @todo -- possibly we can set configuration for this so that users can
// specify which blocks will not get rendered.
if (strpos($block->region, 'sidebar') !== FALSE) {
unset($blocks[$block_id]);
}
}
}

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
82

/**
* Implements hook_modules_enabled().
*
* Clear caches for detecting new plugins.
*/
function ctools_modules_enabled($modules) {
ctools_include('plugins');
ctools_get_plugins_reset();
cache_clear_all('ctools_plugin_files:', 'cache', TRUE);
}

/**
* Implements hook_modules_disabled().
*
* Clear caches for removing disabled plugins.
*/
function ctools_modules_disabled($modules) {
ctools_include('plugins');
ctools_get_plugins_reset();
cache_clear_all('ctools_plugin_files:', 'cache', TRUE);
}

/**
* Menu theme callback.
*

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
83

* This simply ensures that Panels ajax calls are rendered in the same
* theme as the original page to prevent .css file confusion.
*
* To use this, set this as the theme callback on AJAX related menu
* items. Since the ajax page state won't be sent during ajax requests,
* it should be safe to use even if ajax isn't invoked.
*/
function ctools_ajax_theme_callback() {
if (!empty($_POST['ajax_page_state']['theme'])) {
return $_POST['ajax_page_state']['theme'];
}
}

/**
* Implements hook_ctools_entity_context_alter().
*/
function ctools_ctools_entity_context_alter(&$plugin, &$entity, $plugin_id) {
ctools_include('context');
switch ($plugin_id) {
case 'entity_id:taxonomy_term':
$plugin['no ui'] = TRUE;
break;
case 'entity:user':
$plugin = ctools_get_context('user');
unset($plugin['no ui']);
unset($plugin['no required context ui']);
break;

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
84

// Apply restrictions on taxonomy term reverse relationships whose


// restrictions are in the settings on the field.
if (!empty($plugin['parent']) &&
$plugin['parent'] == 'entity_from_field' &&
!empty($plugin['reverse']) &&
$plugin['to entity'] == 'taxonomy_term') {
$field = field_info_field($plugin['field name']);
if (isset($field['settings']['allowed_values'][0]['vocabulary'])) {
$plugin['required context']->restrictions = array('vocabulary' => array($field['settings']
['allowed_values'][0]['vocabulary']));
}
}
}

Code for Installation:

<?php

/**
* @file
* Contains install and update functions for ctools.
*/

/**
* Use requirements to ensure that the CTools CSS cache directory can be

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
85

* created and that the PHP version requirement is met.


*/
function ctools_requirements($phase) {
$requirements = array();
if ($phase == 'runtime') {
$requirements['ctools_css_cache'] = array(
'title' => t('CTools CSS Cache'),
'severity' => REQUIREMENT_OK,
'value' => t('Exists'),
);

$path = 'public://ctools/css';
if (!file_prepare_directory($path, FILE_CREATE_DIRECTORY)) {
$requirements['ctools_css_cache']['description'] = t('The CTools CSS cache directory,
%path could not be created due to a misconfigured files directory. Please ensure that the
files directory is correctly configured and that the webserver has permission to create
directories.', array('%path' => file_uri_target($path)));
$requirements['ctools_css_cache']['severity'] = REQUIREMENT_ERROR;
$requirements['ctools_css_cache']['value'] = t('Unable to create');
}

if (!function_exists('error_get_last')) {
$requirements['ctools_php_52']['title'] = t('CTools PHP requirements');
$requirements['ctools_php_52']['description'] = t('CTools requires certain features only
available in PHP 5.2.0 or higher.');
$requirements['ctools_php_52']['severity'] = REQUIREMENT_WARNING;
$requirements['ctools_php_52']['value'] = t('PHP !version', array('!version' =>

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
86

phpversion()));
}
}

return $requirements;
}

/**
* Implements hook_schema().
*/
function ctools_schema() {
return ctools_schema_3();
}

/**
* Version 3 of the CTools schema.
*/
function ctools_schema_3() {
$schema = ctools_schema_2();

// update the 'obj' field to be 128 bytes long:


$schema['ctools_object_cache']['fields']['obj']['length'] = 128;

return $schema;
}

/**

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
87

* Version 2 of the CTools schema.


*/
function ctools_schema_2() {
$schema = ctools_schema_1();

// update the 'name' field to be 128 bytes long:


$schema['ctools_object_cache']['fields']['name']['length'] = 128;

// Update the 'data' field to be type 'blob'.


$schema['ctools_object_cache']['fields']['data'] = array(
'type' => 'blob',
'size' => 'big',
'description' => 'Serialized data being stored.',
'serialize' => TRUE,
);

// DO NOT MODIFY THIS TABLE -- this definition is used to create the table.
// Changes to this table must be made in schema_3 or higher.
$schema['ctools_css_cache'] = array(
'description' => 'A special cache used to store CSS that must be non-volatile.',
'fields' => array(
'cid' => array(
'type' => 'varchar',
'length' => '128',
'description' => 'The CSS ID this cache object belongs to.',
'not null' => TRUE,
),

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
88

'filename' => array(


'type' => 'varchar',
'length' => '255',
'description' => 'The filename this CSS is stored in.',
),
'css' => array(
'type' => 'text',
'size' => 'big',
'description' => 'CSS being stored.',
'serialize' => TRUE,
),
'filter' => array(
'type' => 'int',
'size' => 'tiny',
'description' => 'Whether or not this CSS needs to be filtered.',
),
),
'primary key' => array('cid'),
);

return $schema;
}

/**
* CTools' initial schema; separated for the purposes of updates.
*
* DO NOT MAKE CHANGES HERE. This schema version is locked.

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
89

*/
function ctools_schema_1() {

7.2 SCREEN SHOTS

Login page

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
90

Registration page:

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
91

Chat web pages

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
92

Profile of user:

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
93

8. TESTING

Web Chat or messengers are trending enormously. The most famous applications are WhatsApp, Facebook,
Google Alo, WeChat etc. There are a lots of chat applications available with new and exciting features but
some of them only success.

This is due to the quality which they maintain and quality comes with testing process, so here I have outlined
those points that would help you understand the process in precise.

Some of the Positive and Non-Functional Test Cases/Scenarios of Web Chat/Functionality are:

1. Verify there are minimum two Users should be available for the chat.

2. Verify there are minimum two devices (Desktop, Laptop, Phones etc) should be available.

3. Verify that Chat application should be launch or evoke.

4. Verify that both side is connected to server.

5. Verify that Users are able to send requests to other Users for chat or not.

6. Verify that how many number of words or characters can be send in a time.

7. Verify that Status (Active, Inactive, Invisible, etc.) of User is changing or not.

8. Verify that User is able to create Account in Chat application or not.

9. Verify that User is able to Login in Chat application or not.

10. Verify that User is able to Login in a system simultaneously with two or more different IDs or not.

11. Verify that User is able to send messages to other offline User.

12. Verify that User is able to see the time of comment in Chat or not.

13. Verify that User is able to sent special characters in Chat or not.

14. Verify that “is it a Forum or Contact us Chat functionality where any user can leave a message or
not?”
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
WEB CHAT SYSTEM
94

15. Verify that User is able to set its profile pic which is visible to other users or not.

16. Verify that Users are able to accept message from other Users for chat or not.

17. Verify that Users are able to Chat with their group or not.

18. Verify that Users are able to see current Chat/discussion in the group.

19. Verify that Users are able to see Chat history of the group or not.

20. Verify that Users are able join current Chat/discussion in their group.

21. Verify that Multiple Users can do Chat or discussion in their group simultaneously and every Chat
should be visible to every member of the group.

22. Verify that Chat application or functionality saves their Chat history or removes after session expire/
Chat application close.

23. Verify that name of the User should be displaying to others in Chat application while chatting with
other Users or group.

24. Verify that whenever any member join or leave the Chat / discussion then it should be notified in the
group and is visible to every member of the group.

25. Verify that User is able to share Image, Video, documents etc or not.

26. Verify that is there any size limit of files if any file (Video, Image, Documents etc.) is uploading and
sharing through the Chat application / functionality.

27. Verify that Chat application is able to display that whether comment or comments have been seen by
the respective User or not.

28. Verify that User is chatting with only original Users not any bot.

29. Verify that User is able to send any emoticons or not.

30. Verify that User is able to Chat with two or more different devices with one ID at a time to other user
or in a group.

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
95

31. Verify that “Does a User is able to login in two different devices at a time or not?”

32. Verify that “How much time is it taking to send a message from one User to another?”

33. Verify that “How much time is it taking to send a message in a group?”

34. Verify that “How long a chat can be saved?”

There are many more Test Cases/Scenarios can be implement because human mind has no limit to think.

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
96

9. CONCLUSION

Online chatting has become increasingly popular. Individuals are no longer hindered from communicating
with each other due to physical barriers such as distance , borders or sea. The most common place for people
to chat is in chat rooms. Many people , especially youngsters , use 'messenger' services like 'Facebook
Messenger' and the newest is 'Whatsapp Messenger' to chat. However , there are advantages and
disadvantages of online chatting.

Firstly , the lack of physical and face-to-face contact makes people more confident and open when chatting.
Chatters remain anonymous , identified only by pseudonyms or nicknames. The lack of identity makes for a
guessing game. Anonymity can also spice up communications , as chatters get caught up in the thrills and
excitement of the guessing game.

In addition , chatting with others in terms of studies helps students to understand different points of view and
leads to a better understanding of what is available in terms of online resources. Meeting with individuals
from different towns , cultures , and countries on the Internet and the exchanging ideas and thoughts can
widen a chatter's horizon. Similarly , chatting to people abroad gives a wider appreciation of global's events
and deeper understanding of the impact of local and international decision making. From chatting with our
Internet acquaintances, our storehpuse of knowledge of other cultures and countries will improve.

On the other hand , online chatting can lead to frightening consequences. Young people make friends easily
and are often willing to give out personal details like their e-mail address, home address and phone
numbers. This might lead to dangerous encounters. Children may be exposed to inappropriate language and
ideas from explicit sexual talk in chat boxes.

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
97

10. FUTURE ENHANCEMENTS

With the knowledge I have gained by developing this application, I am confident that in the future I can
make the application more effectively by adding this services.
 Extending this application by providing Authorisation service.
 Creating Database and maintaining users.
 Increasing the effectiveness of the application by providing Voice Chat.
 Extending it to Web Support.

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS


WEB CHAT SYSTEM
98

11. BIBLIOGRAPHY

 Google for problem solving


 https://www.w3schools.com/pHP/default.asp
 https://www.mysql.com/
 https://stackoverflow.com/
 https://www.youtube.com/playlist?list=PL97E5F049784B72C4

DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS

Potrebbero piacerti anche