• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

cms/modules/pr.lib.php

Go to the documentation of this file.
00001 <?php
00002 if(!defined('__PRAGYAN_CMS'))
00003 { 
00004         header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
00005         echo "<h1>403 Forbidden<h1><h4>You are not authorized to access the page.</h4>";
00006         echo '<hr/>'.$_SERVER['SERVER_SIGNATURE'];
00007         exit(1);
00008 }
00016 // The PR Module is for Public Relations to directly add a user to the Pragyan Website if someone's not registered. The user registered through this is automatically activated also.
00017 class pr implements module {
00018         private $userId;
00019         private $moduleComponentId;
00020         private $action;
00021 
00022         public function getHtml($userId, $moduleComponentId, $action) {
00023                 $this->userId = $userId;
00024                 $this->moduleComponentId = $moduleComponentId;
00025                 $this->action = $action;
00026 
00027                 if($action == 'view') {
00028                         return $this->actionView();
00029                 }
00030         }
00031 
00032         private function getNewUserThirdPartyRegistrationForm() {
00033                 global $sourceFolder, $moduleFolder, $urlRequestRoot,$cmsFolder;
00034                 global $ICONS;
00035                 $registrationForm = <<<REGISTRATIONFORM
00036                         <script language="javascript" type="text/javascript" src="$urlRequestRoot/$cmsFolder/$moduleFolder/pr/pr.js">
00037                         </script>
00038                         <form name="pruserregistrationform" method="POST" action="./+view" onsubmit="return validatePrRegistrationForm(this)">
00039                                 <fieldset style="padding: 8px; margin: 8px">
00040                                         <legend>{$ICONS['PR Add User']['small']}User Information</legend>
00041 
00042                                         <table>
00043                                                 <tr>
00044                                                         <td>Email ID:</label></td>
00045                                                         <td><input type="text" value="" id="txtUserEmail" name="txtUserEmail" /></td>
00046                                                 </tr>
00047                                                 <tr>
00048                                                         <td>User Full Name:</label></td>
00049                                                         <td><input type="text" value="" id="txtUserFullName" name="txtUserFullName" /></td>
00050                                                 </tr>
00051                                                 <tr>
00052                                                         <td>Contact Number:</label></td>
00053                                                         <td><input type="text" value="" id="txtUserPhone" name="txtUserPhone" /></td>
00054                                                 </tr>
00055                                                 <tr>
00056                                                         <td>College/Institution Name:</td>
00057                                                         <td><input type="text" id="txtUserInstitution" name="txtUserInstitution" /></td>
00058                                                 </tr>
00059                                                 <tr>
00060                                                         <td>Password:</td>
00061                                                         <td><input type="password" class="" id="txtUserPassword" name="txtUserPassword" /></td>
00062                                                 </tr>
00063                                                 <tr>
00064                                                         <td>Confirm Password:</td>
00065                                                         <td><input type="password" class="" id="txtUserConfirmPassword" name="txtUserConfirmPassword" /></td>
00066                                                 </tr>
00067                                         </table>
00068                                 </fieldset>
00069 
00070                                 <input type="submit" value="Add User" id="btnAddUser" name="btnAddUser" />
00071                         </form>
00072 
00073 REGISTRATIONFORM;
00074 
00075                 return $registrationForm;
00076         }
00077 
00078         private function submitNewUserThirdPartyRegistrationForm() {
00079                 if(
00080                         isset($_POST['txtUserEmail']) && isset($_POST['txtUserPhone']) && 
00081                         isset($_POST['txtUserInstitution']) && isset($_POST['txtUserPassword']) && isset($_POST['txtUserConfirmPassword'])
00082                 ) {
00083                         if(getUserIdFromEmail(escape($_POST['txtUserEmail']))) {
00084                                 displayerror('The given E-mail Id is already registered on the website. Please use the respective forms\' Edit Registrants view to register the user to events.');
00085                                 return;
00086                         }
00087 
00088                         if ($_POST['txtUserEmail'] == '' || $_POST['txtUserPassword'] == '') {
00089                                 displayerror("Blank e-mail/password NOT allowed");
00090                                 return;
00091                         }
00092                         elseif (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['txtUserEmail'])) {
00093                                 displayerror("Invalid Email Id");
00094                                 return;
00095                         }
00096                         elseif ($_POST['txtUserPassword'] != $_POST['txtUserConfirmPassword']) {
00097                                 displayerror("Passwords are not same");
00098                                 return;
00099                         }
00100 
00101                         $userIdQuery = 'SELECT MAX(`user_id`) FROM `'.MYSQL_DATABASE_PREFIX.'users`';
00102                         $userIdResult = mysql_query($userIdQuery);
00103                         $userIdRow = mysql_fetch_row($userIdResult);
00104 
00105                         $newUserId = 1;
00106                         if(!is_null($userIdRow[0]))
00107                                 $newUserId = $userIdRow[0] + 1;
00108                         $userEmail = escape(trim($_POST['txtUserEmail']));
00109                         $userPassword = $_POST['txtUserPassword'];
00110                         $userContactNumber = escape($_POST['txtUserPhone']);
00111                         $userInstitute = escape($_POST['txtUserInstitution']);
00112                         $userFullName=escape($_POST['txtUserFullName']);
00113                         $insertQuery = 'INSERT INTO `'.MYSQL_DATABASE_PREFIX.'users`(`user_id`, `user_name`, `user_email`, `user_fullname`, `user_password`, `user_regdate`, `user_lastlogin`, `user_activated`) ' .
00114                                         "VALUES($newUserId, '$userFullName', '$userEmail', '$userFullName', MD5('$userPassword'), NOW(), NOW(), 1)";
00115                         $insertResult = mysql_query($insertQuery);
00116 
00117                         if(!$insertResult) {
00118                                 displayerror('Error. Could not add user to database.');
00119                                 return;
00120                         }
00121 
00122                         
00123                         $contactElementId = 3;
00124                         $instituteElementId = 4;
00125                         $contactInsertQuery = 
00126                                         "INSERT INTO `form_elementdata` (`user_id`, `page_modulecomponentid`, `form_elementid`, `form_elementdata`) ".
00127                                         "VALUES " .
00128                                         "($newUserId, 0, $contactElementId, '$userContactNumber'), " .
00129                                         "($newUserId, 0, $instituteElementId, '$userInstitute')";
00130                         $contactInsertResult = mysql_query($contactInsertQuery);
00131                         if(!$contactInsertResult) {
00132                                 displayerror('Could not save the contact number of the user.');
00133                         }
00134                         else displayinfo("User $userEmail has been registered to the pragyan website.");
00135 
00136                 }
00137                 else {
00138                         displayerror('Invalid form submit data.');
00139                 }
00140         }
00141 
00142         public function actionView() {
00143                 if(isset($_POST['btnAddUser'])) {
00144                         $this->submitNewUserThirdPartyRegistrationForm();
00145                 }
00146 
00147                 return $this->getNewUserThirdPartyRegistrationForm();
00148         }
00149 
00150 
00151         public function createModule(&$moduleComponentId) {
00152                 $moduleComponentId = 1;
00153         }
00154 
00155         public function deleteModule($moduleComponentId){
00156         }
00157 
00158         public function copyModule($moduleComponentId){
00159         }
00160 }
00161 

Generated on Sun Jan 2 2011 04:55:32 for Pragyan CMS by  doxygen 1.7.1