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 }
00030 function generateRegistrationForm($moduleCompId,$userId,$action="", $disableCaptcha = false) {
00031 if($action != '')
00032 $userId = getUserIdFromEmail(escape($_GET['useremail']));
00033 else
00034 $action = './+view';
00035
00036 if(!isset($userId)) {
00037 displayerror('Could not load information for user with e-mail address ' . safe_html(escape($_GET['useremail'])));
00038 return '';
00039 }
00040
00042 global $cmsFolder;
00043 global $moduleFolder;
00044 global $urlRequestRoot;
00045 $jsPath2 = "$urlRequestRoot/$cmsFolder/$moduleFolder/form/validation.js";
00046 $jsPath = "$urlRequestRoot/$cmsFolder/templates/common/scripts/formValidator.js";
00047 $calpath = "$urlRequestRoot/$cmsFolder/$moduleFolder";
00048 $jsPathMooTools = "$urlRequestRoot/$cmsFolder/templates/common/scripts/mootools-1.11-allCompressed.js";
00049 $body = '<script language="javascript" type="text/javascript" src="'.$jsPath2.'"></script>';
00050
00051
00053 $jsValidationFunctions = array();
00054 $containsFileUploadFields = false;
00055 $formElements = getFormElementsHtmlAsArray($moduleCompId, $userId, $jsValidationFunctions, $containsFileUploadFields);
00056
00057 $jsValidationFunctions = join($jsValidationFunctions, ' && ');
00058
00059 $body .= '<link rel="stylesheet" type="text/css" media="all" href="'.$calpath.'/form/calendar/calendar.css" title="Aqua" />' .
00060 '<script type="text/javascript" src="'.$calpath.'/form/calendar/calendar.js"></script>';
00061 $body .= '<br /><br /><div class="registrationform"><form class="fValidator-form cms-registrationform" action="'.$action.'" method="post"';
00062 if($containsFileUploadFields)
00063 $body .= ' enctype="multipart/form-data"';
00064 $body .= '>';
00065
00067 $formQuery = 'SELECT `form_heading`, `form_headertext`, `form_footertext`, `form_usecaptcha` FROM `form_desc` WHERE ' .
00068 "`page_modulecomponentid` = $moduleCompId";
00069 $formResult = mysql_query($formQuery);
00070 if(!$formResult) { displayerror('E52 : Invalid query: ' . mysql_error()); return false; }
00071 if($formRow = mysql_fetch_assoc($formResult)) {
00072 $body .= '<fieldset><legend>' . $formRow['form_heading'] . '</legend><br /><div style="text-align:center">' . $formRow['form_headertext'] . '</div><br />';
00073 }
00074 else {
00075 displayerror('Could not load form data.');
00076 return '';
00077 }
00078
00079 $body .= "\n<table cellspacing=\"8px\"><tr>";
00080 $body .= join($formElements, "</tr>\n<tr>") . '</tr>';
00081
00082 if(!$disableCaptcha && $formRow['form_usecaptcha'] == 1)
00083 $body .= getCaptchaHtml();
00084 $req_query = "SELECT count(*) FROM `form_elementdesc` WHERE `form_elementisrequired`=1 AND `page_modulecomponentid`=$moduleCompId";
00085 $res_req = mysql_fetch_array(mysql_query($req_query)) or displayerror("Error at registrationformgenerate.lib.php Line 85 ".mysql_error());
00086 if($res_req[0]>0)
00087 $body .= '<tr>'.
00088 '<td colspan="2">* - Required Fields </td></tr>';
00089 $body .= '</table></fieldset>' .
00090 '<br /><div style="text-align:center"><input type="submit" name="submitreg_form_'.$moduleCompId.'" value="Submit" />' .
00091 '<br /><br />' . $formRow['form_footertext'] .
00092 '</div></form></div>';
00093
00094 $body .= <<<SCRIPT
00095 <script language="javascript" type="text/javascript">
00096 <!--
00097 function validate_form(thisform) {
00098 return ($jsValidationFunctions);
00099 }
00100 -->
00101 </script>
00102 SCRIPT;
00103
00104 return $body;
00105 }
00106
00107 function getCaptchaHtml() {
00108 global $uploadFolder, $sourceFolder, $moduleFolder, $cmsFolder, $urlRequestRoot;
00109 $captcha_query = "SELECT * FROM `". MYSQL_DATABASE_PREFIX."global` WHERE `attribute` = 'recaptcha'";
00110 $captcha_res = mysql_fetch_assoc(mysql_query($captcha_query));
00111 $recaptcha =0;
00112 if($captcha_res['value'])
00113 {
00114 if(!fsockopen("www.google.com",80))
00115 $recaptcha = 0;
00116 else {
00117 $recaptcha =1;
00118 $query = "SELECT `value` FROM `". MYSQL_DATABASE_PREFIX ."global` WHERE `attribute`='recaptcha_public'";
00119 $res = mysql_fetch_assoc(mysql_query($query));
00120 $public_key = $res['value'];
00121 $query = "SELECT `value` FROM `". MYSQL_DATABASE_PREFIX ."global` WHERE `attribute`='recaptcha_private'";
00122 $res = mysql_fetch_assoc(mysql_query($query));
00123 $private_key = $res['value'];
00124 if(($public_key==NULL)||($private_key==NULL))
00125 $recaptcha = 0;
00126 }
00127 if(isset($_GET['recaptcha'])&&($_GET['recaptcha']=="off"))
00128 $recaptcha = 0;
00129 }
00130 if($recaptcha)
00131 {
00132 require_once("$sourceFolder/$moduleFolder/form/captcha/recaptcha/recaptchalib.php");
00133 $body = "<tr><td colspan=2><center>".recaptcha_get_html($public_key)."</center></td></tr>";
00134 $body .= "<tr><td colspan=2>Click <a href='".selfURI()."&recaptcha=off'>here</a> if you can't see the ReCAPTCHA</td></tr>";
00135 $body .="<input type='hidden' name='captcha' value='1'>";
00136 }
00137 else
00138 {
00139 require_once("$sourceFolder/$moduleFolder/form/captcha/class/captcha.class.php");
00140 $captcha = new captcha($sourceFolder, $moduleFolder, $uploadFolder, $urlRequestRoot,$cmsFolder,6);
00141 $_SESSION['CAPTCHAString'] = $captcha->getCaptchaString();
00142
00143 $body = '<tr><td>Enter the text as shown in the image :</td><td>' .
00144 '<img style="border:1px solid;padding:0px" src="' . $captcha->getCaptchaUrl() . '" alt="CAPTCHA" border="1"/><br/>' .
00145 '<input type="text" class="required" name="txtCaptcha" /><td></tr>';
00146 $body .="<input type='hidden' name='captcha' value='0'>";
00147 }
00148 return $body;
00149 }
00150
00151 function getFormElementsHtmlAsArray($moduleCompId, $userId, &$jsValidationFunctions, &$containsFileUploadFields) {
00155 $containsFileUploadFields = false;
00156 $formValues = array();
00157 if(verifyUserRegistered($moduleCompId,$userId)) {
00158 $dataQuery = 'SELECT `form_elementid`, `form_elementdata` FROM `form_elementdata` WHERE ' .
00159 "`page_modulecomponentid` = $moduleCompId AND `user_id` = $userId";
00160 $dataResult = mysql_query($dataQuery);
00161
00162 if(!$dataResult) { displayerror('E35 : Invalid query: ' . mysql_error()); return false; }
00163 while($dataRow = mysql_fetch_assoc($dataResult)) {
00164
00165 $formValues[$dataRow['form_elementid']] = $dataRow['form_elementdata'];
00166 }
00167 }
00168 else {
00169 $dataQuery = 'SELECT `form_elementid`, `form_elementdefaultvalue` FROM `form_elementdesc` WHERE ' .
00170 "`page_modulecomponentid` = $moduleCompId";
00171 $dataResult = mysql_query($dataQuery);
00172
00173 if(!$dataResult) { displayerror('E132 : Invalid query: ' . mysql_error()); return false; }
00174 while($dataRow = mysql_fetch_assoc($dataResult)) {
00175
00176 $formValues[$dataRow['form_elementid']] = $dataRow['form_elementdefaultvalue'];
00177 }
00178 }
00179
00180 $elementQuery = 'SELECT `form_elementid`, `form_elementtype` FROM `form_elementdesc` WHERE ' .
00181 "`page_modulecomponentid` = $moduleCompId ORDER BY `form_elementrank`";
00182 $elementResult = mysql_query($elementQuery);
00183 $formElements = array();
00184 $jsValidationFunctions = array();
00185
00186 while($elementRow = mysql_fetch_row($elementResult)) {
00187 $jsOutput = '';
00188 if($elementRow[1] == 'file') {
00189 $containsFileUploadFields = true;
00190 }
00191
00192 $formElements[] =
00193 getFormElementInputField
00194 (
00195 $moduleCompId, $elementRow[0],
00196 isset($formValues[$elementRow[0]]) ? $formValues[$elementRow[0]] : '', $jsOutput
00197 );
00198 if($jsOutput != '') {
00199 $jsValidationFunctions[] = $jsOutput;
00200 }
00201 }
00202
00203 return $formElements;
00204 }
00205
00206 function getFormElementInputField($moduleComponentId, $elementId, $value="", &$javascriptCheckFunctions) {
00207 $elementQuery = "SELECT * FROM `form_elementdesc` WHERE `page_modulecomponentid` = " .
00208 "$moduleComponentId AND `form_elementid` = $elementId";
00209 $elementResult = mysql_query($elementQuery);
00210
00211 if($elementResult && $elementRow = mysql_fetch_assoc($elementResult)) {
00212 $htmlOutput = '<td>' . $elementRow['form_elementdisplaytext'];
00213 $jsOutput = array();
00214
00215 $elementHelpName = $elementRow['form_elementname'];
00216 $elementType = $elementRow['form_elementtype'];
00217 $elementTooltip = htmlentities($elementRow['form_elementtooltiptext']);
00218 $elementSize = $elementRow['form_elementsize'];
00219 $elementTypeOptions = $elementRow['form_elementtypeoptions'];
00220 $elementMoreThan = $elementRow['form_elementmorethan'];
00221 $elementLessThan = $elementRow['form_elementlessthan'];
00222 $isRequired = $elementRow['form_elementisrequired'];
00223 $elementCheckInt = ($elementRow['form_elementcheckint'])==1?true:false;
00224
00225 $elementName = 'form_' . $moduleComponentId . '_element_' . $elementId;
00226
00227 if($elementRow['form_elementisrequired'] != 0 && ucfirst(strtolower($elementType)) != "Checkbox") {
00228 $jsOutput[] = "isFilled('$elementName', '$elementHelpName')";
00229 }
00230
00231 if($isRequired)
00232 $htmlOutput .= '*';
00233 $htmlOutput .='</td><td>';
00234 if(isset($_POST[$elementName]))
00235 $value = escape($_POST[$elementName]);
00236 $functionName = "getFormElement".ucfirst(strtolower($elementType));
00237 if($functionName($elementName,$value,$isRequired,$elementHelpName,$elementTooltip,$elementSize,$elementTypeOptions,$elementMoreThan,$elementLessThan,$elementCheckInt,$jsOutput,$htmlOutput)==false)
00238 displayerror("Unable to run function ".$functionName);
00239 }
00240
00241 $jsOutput = join($jsOutput, ' && ');
00242 $javascriptCheckFunctions = $jsOutput;
00243
00244 return $htmlOutput . "</td>\n";
00245 }
00246
00247
00249 function getFormElementTextarea($elementName,$value,$isRequired,$elementHelpName,$elementTooltip,$elementSize,$elementTypeOptions,$elementMoreThan,$elementLessThan,$elementCheckInt,&$jsOutput,&$htmlOutput){
00250 $validCheck='';
00251 if($isRequired)
00252 $validCheck=" class=\"required\"";
00253
00254 if(is_numeric($elementSize) && $elementSize > 0) {
00255 $i = $elementSize/5;
00256 $cols = (($i>20)?($i<34?$i:30):20);
00257 $rows = (($cols==20)?5:($cols>27?7:6));
00258 $sizeText = 'rows="'.$rows.'" cols="'.$cols.'"';
00259 }
00260 else
00261 $sizeText = 'rows="5" cols="20"';
00262 $htmlOutput .= '<textarea style="width:100%" '.$sizeText.' name="'.$elementName.'" id="'.$elementName.'" title="'.$elementTooltip."\"".$validCheck.'>' . $value . '</textarea>';
00263 return true;
00264 }
00266 function getFormElementPassword($elementName,$value,$isRequired,$elementHelpName,$elementTooltip,$elementSize,$elementTypeOptions,$elementMoreThan,$elementLessThan,$elementCheckInt,&$jsOutput,&$htmlOutput){
00267
00268 $htmlOutput .= '<input type="password" id="'.$elementName.'" title="'.$elementTooltip.'" />' . $value ;
00269 return true;
00270 }
00272 function getFormElementSelect($elementName,$value,$isRequired,$elementHelpName,$elementTooltip,$elementSize,$elementTypeOptions,$elementMoreThan,$elementLessThan,$elementCheckInt,&$jsOutput,&$htmlOutput)
00273 {
00274 if($isRequired)
00275 $validCheck=" class=\"required\"";
00276 else $validCheck="";
00277 $options = explode('|', $elementTypeOptions);
00278 $optionsHtml = '';
00279 if(isset($_POST[$elementName]))
00280 $value = $options[$value];
00281 for($i = 0; $i < count($options); $i++) {
00282 if($options[$i] == $value) {
00283 $optionsHtml .= '<option value="'.$i.'" selected="selected" >' . $options[$i] . "</option>\n";
00284 }
00285 else {
00286 $optionsHtml .= '<option value="'.$i.'" >' . $options[$i] . "</option>\n";
00287 }
00288 }
00289
00290 $htmlOutput .= '<select name="'.$elementName.'" id="'.$elementName.'" title="'.$elementTooltip."\"".$validCheck.'>' . $optionsHtml . '</select>';
00291 return true;
00292 }
00293
00295 function getFormElementRadio($elementName,$value,$isRequired,$elementHelpName,$elementTooltip,$elementSize,$elementTypeOptions,$elementMoreThan,$elementLessThan,$elementCheckInt,&$jsOutput,&$htmlOutput)
00296 {
00297 if($isRequired)
00298 $validCheck=" class=\"required\"";
00299 else $validCheck="";
00300 $options = explode("|", $elementTypeOptions);
00301 $optionsHtml = '';
00302 if(isset($_POST[$elementName]))
00303 $value = $options[$value];
00304 for($i = 0; $i < count($options); $i++) {
00305 $optionsHtml .= '<label><input type="radio" id="'.$elementName.'" name="'.$elementName.'" value="'.
00306 $i.'"';
00307
00308 if($options[$i] == $value) {
00309 $optionsHtml .= ' checked="checked"';
00310 }
00311
00312 $optionsHtml .= $validCheck.'/>'.$options[$i].'</label> ';
00313 }
00314
00315 $htmlOutput .= $optionsHtml;
00316 return true;
00317 }
00318
00320 function getFormElementCheckbox($elementName,$value,$isRequired,$elementHelpName,$elementTooltip,$elementSize,$elementTypeOptions,$elementMoreThan,$elementLessThan,$elementCheckInt,&$jsOutput,&$htmlOutput)
00321 {
00322 $options = explode("|", $elementTypeOptions);
00323 $validCheck = "";
00324 if($isRequired)
00325 $jsOutput[] = "isChecked('$elementName','$elementHelpName',".count($options).")";
00326 if(isset($_POST[$elementName."_0"])){
00327 $i=-1;
00328 $value = array();
00329 foreach($options as $val) {
00330 $i++;
00331 if(!isset($_POST[$elementName."_".$i]))
00332 continue;
00333 $value[] = $val;
00334 }
00335 $value = join($value,"|");
00336 }
00337 $optionsHtml = '';
00338 $values=explode("|",$value);
00339 for($i = 0; $i < count($options); $i++) {
00340 $optionsHtml .= '<label><input type="checkbox" id="'.$elementName.'_'.$i.'" name="'.$elementName.'_'.$i.'" value="'.
00341 htmlentities($options[$i]).'"';
00342
00343 if(array_search($options[$i],$values)!==FALSE) {
00344 $optionsHtml .= ' checked="checked"';
00345 }
00346
00347 $optionsHtml .= $validCheck.' />'.$options[$i].'</label> ';
00348 }
00349
00350 $htmlOutput .= $optionsHtml;
00351 return true;
00352 }
00353
00355 function getFormElementFile($elementName,$value,$isRequired,$elementHelpName,$elementTooltip,$elementSize,$elementTypeOptions,$elementMoreThan,$elementLessThan,$elementCheckInt,&$jsOutput,&$htmlOutput)
00356 {
00357 if($isRequired && $value == '')
00358 $validCheck=" class=\"required\"";
00359 else
00360 $validCheck="";
00361
00362 global $sourceFolder;
00363 require_once("$sourceFolder/upload.lib.php");
00364 $htmlOutput .= getFileUploadField($elementName,"form", 2*1024*1024, $validCheck);
00365
00366 global $uploadFolder;
00367 if($value != '') {
00368 $htmlOutput .= '<br />(Leave blank to keep current file : <a href="./' . $value . '">'.$value.'</a>)';
00369 }
00370
00371 return true;
00372 }
00373
00375 function getFormElementText($elementName,$value,$isRequired,$elementHelpName,$elementTooltip,$elementSize,$elementTypeOptions,$elementMoreThan,$elementLessThan,$elementCheckInt,&$jsOutput,&$htmlOutput)
00376 {
00377 if($isRequired)
00378 $validCheck=" class=\"required\"";
00379 else $validCheck="";
00380 if($elementCheckInt)
00381 {
00382 if($validCheck!="")
00383 $validCheck=" class=\"required numeric\"";
00384 else
00385 $validCheck=" class=\"numeric\"";
00386
00387 if(!is_null($elementMoreThan) && $elementMoreThan!="")
00388 $validCheck .= ' min="' . ($elementMoreThan + 1) . '"';
00389 if(!is_null($elementLessThan) && $elementLessThan!="")
00390 $validCheck .= ' max="' . ($elementLessThan - 1) . '"';
00391 }
00392 if(is_numeric($elementSize) && $elementSize > 0) {
00393 $maxlength = $elementSize;
00394 if($elementSize > 30)
00395 $elementSize = 30;
00396 $sizeText = 'maxlength="'.$maxlength.'" size="'.$elementSize.'"';
00397 }
00398 else
00399 $sizeText = "";
00400 $htmlOutput .= '<input type="text" '.$sizeText.' name="'.$elementName.'" id="'.$elementName.'" value="'.$value.'" ' .
00401 'title="'.$elementTooltip."\"".$validCheck.' />';
00402 return true;
00403 }
00404
00406 function getFormElementDate($elementName,$value,$isRequired,$elementHelpName,$elementTooltip,$elementSize,$elementTypeOptions,$elementMoreThan,$elementLessThan,$elementCheckInt,&$jsOutput,&$htmlOutput)
00407 {
00408 return getFormElementDatetime($elementName,$value,$isRequired,$elementHelpName,$elementTooltip,$elementSize,$elementTypeOptions,$elementMoreThan,$elementLessThan,$elementCheckInt,$jsOutput,$htmlOutput,"date");
00409 }
00410 function getFormElementDatetime($elementName,$value,$isRequired,$elementHelpName,$elementTooltip,$elementSize,$elementTypeOptions,$elementMoreThan,$elementLessThan,$elementCheckInt,&$jsOutput,&$htmlOutput,$type="datetime")
00411 {
00412 $datetimeFormat = ($type == 'date' ? "'%Y-%m-%d'" : "'%Y-%m-%d %H:%M'");
00413
00414 if($isRequired)
00415 $validCheck=' class="required"';
00416 else
00417 $validCheck="";
00418
00419 $validCheck .= ' dateformat="' . ($type == 'date' ? 'YY-MM-DD' : 'YY-MM-DD hh:mm') . '"';
00420
00421 if(!is_null($elementMoreThan) && $elementMoreThan != '') {
00422 $jsOutput[] = "checkLBDate('$elementName', '$elementMoreThan', $datetimeFormat, '$elementHelpName')";
00423 }
00424 if(!is_null($elementLessThan) && $elementLessThan != '') {
00425 $jsOutput[] = "checkUBDate('$elementName', '$elementLessThan', $datetimeFormat, '$elementHelpName')";
00426 }
00427 $htmlOutput .= '<input type="text" '. $validCheck . ' name="'.$elementName.'" value="' . $value . '" id="'.$elementName.'" /><input name="cal'.$elementName.'" type="reset" value=" ... " onclick="return showCalendar(\'' . $elementName . '\', '.$datetimeFormat.', \'24\', true);" />';
00428 return true;
00429 }