PageRenderTime 74ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/sfd2010/register/form.lib.php

https://bitbucket.org/rajeshwar/osum_by_r
PHP | 1787 lines | 1348 code | 361 blank | 78 comment | 229 complexity | 892c420f0f496f729d72e20e31a92c5a MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. # PHPFMG_ID:'20100906-7274'
  3. # Date : 20100906 14:04:31
  4. # Generated By Free PHP Formmail Generator : http://smvdu.net.in
  5. # -----------------------------------------------------------------------------
  6. define( 'PAYPAL_ID' , '' ); // Put donation ID here to disable the copyright link
  7. define( 'PHPFMG_ID' , '20100906-7274' );
  8. define( 'PHPFMG_TO' , 'thes.kumar@gmail.com' );
  9. define( 'PHPFMG_REDIRECT', '' );
  10. define( 'PHPFMG_ROOT_DIR' , dirname(__FILE__) );
  11. define( 'PHPFMG_SAVE_FILE' , PHPFMG_ROOT_DIR . '/form-data-log.php' ); // save submitted data to this file
  12. define( 'PHPFMG_EMAILS_LOGFILE' , PHPFMG_ROOT_DIR . '/email-traffics-log.php' ); // log email traffics to this file
  13. define( 'PHPFMG_ADMIN_URL' , 'admin.php' );
  14. define( 'PHPFMG_SAVE_ATTACHMENTS' , '' );
  15. define( 'PHPFMG_SAVE_ATTACHMENTS_DIR' , PHPFMG_ROOT_DIR . '/uploaded/' );
  16. // three options : empty - always mail file as attachment, 0 - always mail file as link, N - mail file as link if filesize larger than N Kilobytes
  17. define( 'PHPFMG_FILE2LINK_SIZE' , '' );
  18. define( 'PHPFMG_UPLOAD_CONTROL' , '' );
  19. define( 'PHPFMG_HARMFUL_EXTS' , ".php, .html, .css, .js, .exe, .com, .bat, .vb, .vbs, scr, .inf, .reg, .lnk, .pif, .ade, .adp, .app, .bas, .chm, .cmd, .cpl, .crt, .csh, .fxp, .hlp, .hta, .ins, .isp, .jse, .ksh, .Lnk, .mda, .mdb, .mde, .mdt, .mdw, .mdz, .msc, .msi, .msp, .mst, .ops, .pcd, .prf, .prg, .pst, .scf, .scr, .sct, .shb, .shs, .url, .vbe, .wsc, .wsf, .wsh" );
  20. define( 'PHPFMG_HARMFUL_EXTS_MSG' , 'File is potential harmful. Upload is not allowed.' );
  21. define( 'PHPFMG_ALLOW_EXTS' , ".jpg, .gif, .png, .bmp" );
  22. define( 'PHPFMG_ALLOW_EXTS_MSG' , "Upload is not allowed. Please check your file type." );
  23. define( 'PHPFMG_CC' , '' );
  24. define( 'PHPFMG_BCC', '' );
  25. define( 'PHPFMG_SUBJECT' , "Registration Details: SFD2010" );
  26. define( 'PHPFMG_RETURN_SUBJECT' , "Thanks for registering for SFD2010 @ SMVDU" ); // auto response mail subject
  27. define( 'PHPFMG_CHARSET' , 'UTF-8' );
  28. define( 'PHPFMG_MAIL_TYPE' , 'html' ); // send mail in html format or plain text.
  29. define( 'PHPFMG_ACTION' , 'mailandfile' ); // delivery method
  30. define( 'PHPFMG_TEXT_ALIGN' , 'left' ); // field label text alignment: top, right, left
  31. define( 'PHPFMG_NO_FROM_HEADER' , '' ); // don't make up From: header.
  32. define( 'PHPFMG_SENDMAIL_FROM' , '' ); // force sender's email
  33. define( 'PHPFMG_SMTP' , '' ); // send email via this SMTP server
  34. define( 'HOST_NAME',getEnv( 'SERVER_NAME' ) );
  35. define( 'PHP_SELF', getEnv( 'SCRIPT_NAME' ) );
  36. define( 'PHPFMG_LNCR', "\x0d\x0a" );
  37. define( 'PHPFMG_ANTI_HOTLINKING' , '' );
  38. define( 'PHPFMG_REFERERS_ALLOW', "" ); // Referers - domains/ips that you will allow forms to reside on.
  39. define( 'PHPFMG_REFERERS_DENIED_MSG', "You are coming from an <b>unauthorized domain.</b>" );
  40. # -----------------------------------------------------------------------------
  41. set_magic_quotes_runtime(0);
  42. error_reporting( E_ERROR );
  43. session_start();
  44. phpfmg_check_referers();
  45. # -----------------------------------------------------------------------------
  46. function phpfmg_thankyou(){
  47. phpfmg_redirect_js();
  48. ?>
  49. <!-- [Your confirmation message goes here] --------------------------------->
  50. <br>
  51. <b>Thank you registering at SFD2010.
  52. Get your gears ready for the 18th Sept 2010.
  53. </b>
  54. <br><br>
  55. <?php
  56. } // end of function phpfmg_thankyou()
  57. function phpfmg_auto_response_message(){
  58. ob_start();
  59. ?>
  60. Hi %NameOfSender%,
  61. Thank you for registering for Software Freedom Day Celebration at Shri Mata Vaishno Devi University (SMVDU):
  62. Your Registration Details are as follows:
  63. %DataOfForm%
  64. Reference ID: %AutoID%
  65. The Club really appreciates you effort. 18th September would be yours... prepare yourself...
  66. Till then you may subscribe to us http://groups.google.com/group/osumsmvduclub
  67. to remain updated.
  68. Regards,
  69. OSUM SMVDU Club
  70. Date: %Date%
  71. <?php
  72. $msg = ob_get_contents() ;
  73. ob_end_clean();
  74. return trim($msg);
  75. }
  76. function phpfmg_mail_template(){
  77. ob_start();
  78. ?>
  79. %TitleOfSender% %NameOfSender%.. registered for SFD 2010.
  80. The registration Details are as follows.
  81. %DataOfForm%
  82. Reference ID: %AutoID%
  83. Cheers,
  84. Web Incharge
  85. OSUM SMVDU Club
  86. Date: %Date% | Time: %Time%
  87. <?php
  88. $msg = ob_get_contents() ;
  89. ob_end_clean();
  90. return trim($msg);
  91. }
  92. # --- Array of Form Elements ---
  93. $form_mail['field_0'] = array( "name" => "field_0", "text" => "Your Name", "type" => "sender's name", "instruction" => "", "required" => "Required" ) ;
  94. $form_mail['field_1'] = array( "name" => "field_1", "text" => "Your Email", "type" => "sender's email", "instruction" => "All Further Communication with us will happen through this email.", "required" => "Required" ) ;
  95. $form_mail['field_2'] = array( "name" => "field_2", "text" => "", "type" => "sectionbreak", "instruction" => "", "required" => "Not Required" ) ;
  96. $form_mail['field_3'] = array( "name" => "field_3", "text" => "Name of your Institute", "type" => "text", "instruction" => "", "required" => "Required" ) ;
  97. $form_mail['field_4'] = array( "name" => "field_4", "text" => "Enrollment/Entry No.", "type" => "text", "instruction" => "", "required" => "" ) ;
  98. $form_mail['field_5'] = array( "name" => "field_5", "text" => "", "type" => "sectionbreak", "instruction" => "", "required" => "Not Required" ) ;
  99. $form_mail['field_6'] = array( "name" => "field_6", "text" => "Event you\'ll be paticipating in", "type" => "select", "instruction" => "", "required" => "" ) ;
  100. $form_mail['field_7'] = array( "name" => "field_7", "text" => "", "type" => "sectionbreak", "instruction" => "", "required" => "Not Required" ) ;
  101. $form_mail['field_8'] = array( "name" => "field_8", "text" => "Queries (if any)", "type" => "textarea", "instruction" => "", "required" => "" ) ;
  102. ?>
  103. <?php
  104. function phpfmg_display_form(){
  105. global $form_mail;
  106. @header( 'Content-Type: text/html; charset=' . PHPFMG_CHARSET );
  107. $phpfmg_send = phpfmg_sendmail( $form_mail ) ;
  108. $isHideForm = isset($phpfmg_send['isHideForm']) ? $phpfmg_send['isHideForm'] : false;
  109. $sErr = isset($phpfmg_send['error']) ? $phpfmg_send['error'] : '';
  110. # FormMail main()
  111. phpfmg_header();
  112. if( !$isHideForm ){
  113. phpfmg_form($sErr);
  114. }else{
  115. phpfmg_thankyou();
  116. };
  117. phpfmg_footer();
  118. return;
  119. }
  120. function phpfmg_sendmail( &$form_mail ) {
  121. if( !isset($_POST["formmail_submit"]) ) return ;
  122. $isHideForm = false ;
  123. $sErr = checkPass($form_mail);
  124. $err_captcha = phpfmg_check_captcha();
  125. if( $err_captcha != '' ){
  126. $sErr['fields'][] = 'phpfmg_captcha';
  127. $sErr['errors'][] = ERR_CAPTCHA;
  128. };
  129. if( empty($sErr['fields']) ){
  130. if( defined('PHPFMG_SENDMAIL_FROM') && '' != PHPFMG_SENDMAIL_FROM ){
  131. ini_set("sendmail_from", PHPFMG_SENDMAIL_FROM);
  132. };
  133. if( defined('PHPFMG_SMTP') && '' != PHPFMG_SMTP ){
  134. ini_set("SMTP", PHPFMG_SMTP);
  135. };
  136. sendFormMail( $form_mail, PHPFMG_SAVE_FILE ) ;
  137. $isHideForm = true;
  138. // move the redirect to phpfmg_thankyou() to get around the redirection within an iframe problem
  139. /*
  140. $redirect = PHPFMG_REDIRECT;
  141. if( strlen(trim($redirect)) ):
  142. header( "Location: $redirect" );
  143. exit;
  144. endif;
  145. */
  146. };
  147. return array(
  148. 'isHideForm' => $isHideForm,
  149. 'error' => $sErr ,
  150. );
  151. }
  152. function sendFormMail( $form_mail, $sFileName = "" )
  153. {
  154. $to = filterEmail(PHPFMG_TO) ;
  155. $cc = filterEmail(PHPFMG_CC) ;
  156. $bcc = filterEmail(PHPFMG_BCC) ;
  157. // simply chop email address to avoid my website being abused
  158. if( false !== strpos( strtolower($_SERVER['HTTP_HOST']),'formmail-maker.com') ){
  159. $cc = substr($cc, 0, 50);
  160. $bcc = substr($bcc,0, 50);
  161. };
  162. $subject = PHPFMG_SUBJECT ;
  163. $from = $to ;
  164. $fromName = "";
  165. $titleOfSender = '';
  166. $strip = get_magic_quotes_gpc() ;
  167. $content = '' ;
  168. $style = 'font-family:Verdana, Arial, Helvetica, sans-serif; font-size : 13px; color:#474747;padding:6px;border-bottom:1px solid #cccccc;' ;
  169. $tr = array() ; // html table
  170. $csvValues = array();
  171. $cols = array();
  172. $replace = array();
  173. $RecordID = phpfmg_getRecordID();
  174. $isWritable = is_writable( dirname(PHPFMG_SAVE_ATTACHMENTS_DIR) );
  175. foreach( $form_mail as $field ){
  176. $field_type = strtolower($field[ "type" ]);
  177. if( 'sectionbreak' == $field_type ){
  178. continue;
  179. };
  180. $value = trim( $_POST[ $field[ "name" ] ] );
  181. $value = $strip ? stripslashes($value) : $value ;
  182. if( 'attachment' == $field_type ){
  183. $value = $isWritable ? phpfmg_file2value( $RecordID, $_FILES[ $field[ "name" ] ] ) : $_FILES[ $field[ "name" ] ]['name'];
  184. //$value = $_FILES[ $field[ "name" ] ]['name'];
  185. };
  186. $content .= $field[ "text" ] . " \t : " . $value .PHPFMG_LNCR;
  187. $tr[] = "<tr> <td valign=top style='{$style};width:300px;border-right:1px solid #cccccc;'>" . $field[ "text" ] . "&nbsp;</td> <td valign=top style='{$style};'>" . nl2br($value) . "&nbsp;</td></tr>" ;
  188. $csvValues[] = csvfield( $value );
  189. $cols[] = csvfield( $field[ "text" ] );
  190. $replace["%".$field[ "name" ]."%"] = $value;
  191. switch( $field_type ){
  192. case "sender's email" :
  193. $from = filterEmail($value) ;
  194. break;
  195. case "sender's name" :
  196. $fromName = filterEmail($value) ;
  197. break;
  198. case "titleofsender" :
  199. $titleOfSender = $value ;
  200. break;
  201. default :
  202. // nothing
  203. };
  204. }; // for
  205. $isHtml = 'html' == PHPFMG_MAIL_TYPE ;
  206. if( $isHtml ) {
  207. $content = "<table cellspacing=0 cellpadding=0 border=0 >" . PHPFMG_LNCR . join( PHPFMG_LNCR, $tr ) . PHPFMG_LNCR . "</table>" ;
  208. };
  209. $fromHeader = filterEmail( ('' != $fromName ? "\"$fromName\"" : '' ) . " <{$from}>",array(",", ";")) ; // no multiple emails are allowed.
  210. $_fields = array(
  211. '%NameOfSender%' => $fromName,
  212. '%EmailOfSender%' => $from,
  213. '%TitleOfSender%' => $titleOfSender,
  214. '%DataOfForm%' => $content,
  215. '%IP%' => $_SERVER['REMOTE_ADDR'],
  216. '%Date%' => date("Y-m-d"),
  217. '%Time%' => date("H:i:s"),
  218. '%AutoID%' => $RecordID,
  219. );
  220. $fields = array_merge( $_fields, $replace );
  221. $esh_mail_template = trim(phpfmg_mail_template());
  222. if( !empty($esh_mail_template) ){
  223. $esh_mail_template = phpfmg_adjust_template($esh_mail_template);
  224. $content = phpfmg_parse_mail_body( $esh_mail_template, $fields );
  225. };
  226. $subject = phpfmg_parse_mail_body( $subject, $fields );
  227. if( $isHtml ) {
  228. $content = phpfmg_getHtmlContent( $content );
  229. };
  230. $oldMask = umask(0);
  231. //$sep = ','; //chr(0x09);
  232. $sep = chr(0x09);
  233. $recordCols = phpfmg_data2record( csvfield('RecordID') . $sep . csvfield('Date') . $sep . csvfield('IP') . $sep . join($sep,$cols) );
  234. $record = phpfmg_data2record( csvfield($RecordID) . $sep . csvfield(date("Y-m-d H:i:s")) . $sep . csvfield($_SERVER['REMOTE_ADDR']) .$sep . join($sep,$csvValues) );
  235. switch( strtolower(PHPFMG_ACTION) ){
  236. case 'fileonly' :
  237. appendToFile( $sFileName, $record, $recordCols );
  238. break;
  239. case 'mailonly' :
  240. mailAttachments( $to , $subject , $content, $fromHeader, $cc , $bcc, PHPFMG_CHARSET ) ;
  241. break;
  242. case 'mailandfile' :
  243. default:
  244. mailAttachments( $to , $subject , $content, $fromHeader, $cc , $bcc, PHPFMG_CHARSET ) ;
  245. appendToFile( $sFileName, $record, $recordCols );
  246. }; // switch
  247. //mailReport( $content, $sFileName );
  248. mailAutoResponse( $from, $to, $fields ) ;
  249. umask($oldMask);
  250. }
  251. function phpfmg_file2value( $recordID, $file ){
  252. $tmp = $file[ "tmp_name" ] ;
  253. $name = phpfmg_rename_harmful(trim($file[ "name" ])) ;
  254. if( !defined('PHPFMG_FILE2LINK_SIZE') ){
  255. return $name;
  256. };
  257. if( is_uploaded_file( $tmp ) ) {
  258. $size = trim(PHPFMG_FILE2LINK_SIZE) ;
  259. switch( $size ){
  260. case '' :
  261. return $name;
  262. default:
  263. $isHtml = 'html' == PHPFMG_MAIL_TYPE;
  264. $filelink= base64_encode( serialize(array('recordID'=>$recordID, 'filename'=>$name)) );
  265. $url = phpfmg_admin_url() . "?mod=filman&func=download&filelink=" . urlencode($filelink) ;
  266. $isLarger = (filesize($tmp)/1024) > $size ;
  267. $link = $isHtml ? "<a href='{$url}'>$name</a>" : $name . " ( {$url} )";
  268. return $isLarger ? $link : $name ; // email download link when size is larger defined size, otherwise send as attachment
  269. };// switch
  270. }; // if
  271. return $name;
  272. }
  273. function phpfmg_dir2unix( $dir ){
  274. return str_replace( array("\\", '//'), '/', $dir );
  275. }
  276. function phpfmg_request_uri(){
  277. $uri = getEnv('REQUEST_URI'); // apache has this
  278. if( false !== $uri && strlen($uri) > 0 ){
  279. return $uri ;
  280. } else {
  281. $uri = ($uri = getEnv('SCRIPT_NAME')) !== false
  282. ? $uri
  283. : getEnv('PATH_INFO') ;
  284. $qs = getEnv('QUERY_STRING'); // IIS and Apache has this
  285. return $uri . ( empty($qs) ? '' : '?' . $qs );
  286. };
  287. return "" ;
  288. }
  289. // parse full admin url to view large size uploaded file online
  290. function phpfmg_admin_url(){
  291. $http_host = "http://{$_SERVER['HTTP_HOST']}";
  292. switch( true ){
  293. case (0 === strpos(PHPFMG_ADMIN_URL, 'http://' )) :
  294. $url = PHPFMG_ADMIN_URL;
  295. break;
  296. case ( '/' == substr(PHPFMG_ADMIN_URL,0,1) ) :
  297. $url = $http_host . PHPFMG_ADMIN_URL ;
  298. break;
  299. default:
  300. $uri = phpfmg_request_uri();
  301. $pos = strrpos( $uri, '/' );
  302. $vdir = substr( $uri, 0, $pos );
  303. $url = $http_host . $vdir . '/' . PHPFMG_ADMIN_URL ;
  304. };
  305. return $url;
  306. }
  307. function phpfmg_ispost(){
  308. return 'POST' == strtoupper($_SERVER["REQUEST_METHOD"]) || 'POST' == strtoupper(getEnv('REQUEST_METHOD')) ;
  309. }
  310. // don't allow hotlink form to my website. To avoid people create phishing form.
  311. function phpfmg_hotlinking_mysite(){
  312. $yes = false !== strpos( strtolower($_SERVER['HTTP_HOST']),'formmail-maker.com') // accessing form at mysite
  313. && ( empty($_SERVER['HTTP_REFERER']) || false === strpos( strtolower($_SERVER['HTTP_REFERER']),'formmail-maker.com') ) ; // doesn't have referer of mysite
  314. if( $yes ){
  315. die( "<b>Access Denied.</b>
  316. <br /><br />
  317. You are visiting a form hotlinkink from <a href='http://www.formmail-maker.com'>formmail-maker.com</a> which is not allowed.
  318. Please read the <a href='http://www.formmail-maker.com/web-form-mail-faq.php'>FAQ</a>.
  319. " );
  320. };
  321. }
  322. function phpfmg_check_referers(){
  323. phpfmg_hotlinking_mysite(); // anti phishing
  324. $debugs = array();
  325. $debugs[] = "Your IP: " . $_SERVER['REMOTE_ADDR'];
  326. $debugs[] = "Referer link: " . $_SERVER['HTTP_REFERER'];
  327. $debugs[] = "Host of referer: $referer";
  328. $check = defined('PHPFMG_ANTI_HOTLINKING') && 'Y' == PHPFMG_ANTI_HOTLINKING;
  329. if( !$check ) {
  330. $debugs[] = "Referer is empty. No need to check hot linking.";
  331. //echo "<pre>" . join("\n",$debugs) . "</pre>\n";
  332. //appendToFile( PHPFMG_EMAILS_LOGFILE, date("Y-m-d H:i:s") . "\t" . $_SERVER['REMOTE_ADDR'] . " \n" . join("\n",$debugs) ) ;
  333. return true;
  334. };
  335. // maybe post from local file
  336. if( !isset($_SERVER['HTTP_REFERER']) && phpfmg_ispost() ){
  337. appendToFile( PHPFMG_EMAILS_LOGFILE, date("Y-m-d H:i:s") . "\t" . $_SERVER['REMOTE_ADDR'] . " \n phpfmg_ispost " . join("\n",$debugs) ) ;
  338. die( PHPFMG_REFERERS_DENIED_MSG );
  339. };
  340. $url = parse_url($_SERVER['HTTP_REFERER']);
  341. $referer = str_replace( 'www.', '', strtolower($url['host']) );
  342. if( empty($referer) ) {
  343. return true;
  344. };
  345. $hosts = explode(',',PHPFMG_REFERERS_ALLOW);
  346. $http_host = strtolower($_SERVER['HTTP_HOST']);
  347. $referer = $http_host ;
  348. $hosts[] = str_replace('www.', '', $http_host );
  349. $debugs[] = "Hosts Allow: " . PHPFMG_REFERERS_ALLOW;
  350. $allow = false ;
  351. foreach( $hosts as $host ){
  352. $host = strtolower(trim($host));
  353. $debugs[] = "check host: $host " ;
  354. if( false !== strpos($referer, $host) || false !== strpos($referer, 'www.'.$host) ){
  355. $allow = true;
  356. $debugs[] = " -> allow (quick exit)";
  357. break;
  358. }else{
  359. $debugs[] = " -> deny";
  360. };
  361. };
  362. //echo "<pre>" . join("\n",$debugs) . "</pre>\n";
  363. //appendToFile( PHPFMG_EMAILS_LOGFILE, date("Y-m-d H:i:s") . "\t" . $_SERVER['REMOTE_ADDR'] . " \n" . join("\n",$debugs) ) ;
  364. if( !$allow ){
  365. die( PHPFMG_REFERERS_DENIED_MSG );
  366. };
  367. }
  368. function phpfmg_getRecordID(){
  369. if( !isset($GLOBALS['RecordID']) ){
  370. $GLOBALS['RecordID'] = date("Ymd") . '-'. substr( md5(uniqid(rand(), true)), 0,4 );
  371. };
  372. return $GLOBALS['RecordID'];
  373. }
  374. function phpfmg_data2record( $s, $b=true ){
  375. $from = array( "\r", "\n");
  376. $to = array( "\\r", "\\n" );
  377. return $b ? str_replace( $from, $to, $s ) : str_replace( $to, $from, $s ) ;
  378. }
  379. function csvfield( $str ){
  380. $str = str_replace( '"', '""', $str );
  381. return '"' . trim($str) . '"';
  382. }
  383. function mailAttachments( $to = "" , $subject = "" , $message = "" , $from = "" , $cc = "" , $bcc = "", $charset = "UTF-8", $type = 'FormMail' ){
  384. if( ! strlen( trim( $to ) ) ) return "Missing \"To\" Field." ;
  385. $boundary = "====_My_PHP_Form_Generator_" . md5( uniqid( srand( time() ) ) ) . "====";
  386. $content_type = 'html' == PHPFMG_MAIL_TYPE ? "text/html" : "text/plain" ;
  387. // setup mail header infomation
  388. $headers = 'Y' == PHPFMG_NO_FROM_HEADER ? '' : "From: $from" .PHPFMG_LNCR;
  389. if ($cc) $headers .= "CC: $cc".PHPFMG_LNCR;
  390. if ($bcc) $headers .= "BCC: $bcc".PHPFMG_LNCR;
  391. //$headers .= "Content-type: {$content_type}; charset={$charset}" .PHPFMG_LNCR ;
  392. $plainHeaders = $headers ; // for no attachments header
  393. $plainHeaders .= 'MIME-Version: 1.0' . PHPFMG_LNCR;
  394. $plainHeaders .= "Content-type: {$content_type}; charset={$charset}" ;
  395. //create mulitipart attachments boundary
  396. $sError = "" ;
  397. $nFound = 0;
  398. if( array_key_exists($GLOBALS['phpfmg_files_content']) && '' != $GLOBALS['phpfmg_files_content'] ){
  399. // use previous encoded content
  400. $sEncodeBody = $GLOBALS['phpfmg_files_content'] ;
  401. $nFound = true ;
  402. }else{
  403. $file2link_size = trim(PHPFMG_FILE2LINK_SIZE) ;
  404. $isSave = ('' != $file2link_size || defined('PHPFMG_SAVE_ATTACHMENTS') && 'Y' == PHPFMG_SAVE_ATTACHMENTS);
  405. if( $isSave ){
  406. if( defined('PHPFMG_SAVE_ATTACHMENTS_DIR') ){
  407. if( !is_dir(PHPFMG_SAVE_ATTACHMENTS_DIR) ){
  408. $ok = @mkdir( PHPFMG_SAVE_ATTACHMENTS_DIR, 0777 );
  409. if( !$ok ) $isSave = false;
  410. };
  411. };
  412. };
  413. $isWritable = is_writable( dirname(PHPFMG_SAVE_ATTACHMENTS_DIR) );
  414. // parse attachments content
  415. foreach( $_FILES as $aFile ){
  416. $sFileName = $aFile[ "tmp_name" ] ;
  417. $sFileRealName = phpfmg_rename_harmful($aFile[ "name" ]) ;
  418. if( is_uploaded_file( $sFileName ) ):
  419. $isSkip = '' != $file2link_size && ( (filesize($sFileName)/1024) > $file2link_size );
  420. // save uploaded file
  421. if( $isWritable && $isSave ){
  422. $tofile = PHPFMG_SAVE_ATTACHMENTS_DIR . phpfmg_getRecordID() . '-' . basename($sFileRealName);
  423. if( @copy( $sFileName, $tofile) ) chmod($tofile,0777);
  424. };
  425. if( $isSkip )
  426. continue; // mail file as link
  427. if( $fp = @fopen( $sFileName, "rb" ) ) :
  428. $sContent = fread( $fp, filesize( $sFileName ) );
  429. $sFName = basename( $sFileRealName ) ;
  430. $sMIME = getMIMEType( $sFName ) ;
  431. $bPlainText = ( $sMIME == "text/plain" ) ;
  432. if( $bPlainText ) :
  433. $encoding = "" ;
  434. else:
  435. $encoding = "Content-Transfer-Encoding: base64".PHPFMG_LNCR;
  436. $sContent = chunk_split( base64_encode( $sContent ) );
  437. endif;
  438. $sEncodeBody .= PHPFMG_LNCR."--$boundary" .PHPFMG_LNCR.
  439. "Content-Type: $sMIME;" . PHPFMG_LNCR.
  440. "\tname=\"$sFName\"" . PHPFMG_LNCR.
  441. $encoding .
  442. "Content-Disposition: attachment;" . PHPFMG_LNCR.
  443. "\tfilename=\"$sFName\"" . PHPFMG_LNCR. PHPFMG_LNCR.
  444. $sContent . PHPFMG_LNCR ;
  445. $nFound ++;
  446. else:
  447. $sError .= "<br>Failed to open file $sFileName.\n" ;
  448. endif; // if( $fp = fopen( $sFileName, "rb" ) ) :
  449. else:
  450. $sError .= "<br>File $sFileName doesn't exist.\n" ;
  451. endif; //if( file_exists( $sFileName ) ):
  452. }; // end foreach
  453. $sEncodeBody .= PHPFMG_LNCR.PHPFMG_LNCR."--$boundary--" ;
  454. }; // if
  455. $headers .= "MIME-Version: 1.0".PHPFMG_LNCR."Content-type: multipart/mixed;".PHPFMG_LNCR."\tboundary=\"$boundary\"";
  456. $txtMsg = PHPFMG_LNCR."This is a multi-part message in MIME format." .PHPFMG_LNCR .
  457. PHPFMG_LNCR."--$boundary" .PHPFMG_LNCR .
  458. "Content-Type: {$content_type};".PHPFMG_LNCR.
  459. "\tcharset=\"$charset\"" .PHPFMG_LNCR.PHPFMG_LNCR .
  460. $message . PHPFMG_LNCR;
  461. $body = $nFound ? $txtMsg . $sEncodeBody : $message ;
  462. $headers = $nFound ? $headers : $plainHeaders ;
  463. $ok = mail( $to, $subject, $body, $headers );
  464. $status = $ok ? "\n[Email sent]" : "\n[Failed to send mail]" ;
  465. phpfmg_log_mail( $to, $subject, ($ok ? 'Email sent' : 'Failed to send mail') . "\n" . ($nFound ? $headers . $txtMsg : $headers . $message), '', $type . $status ); // no log for attachments
  466. return $sError ;
  467. }
  468. function mailAutoResponse( $to, $from, $fields = false ){
  469. if( !formIsEMail($to) ) return ERR_EMAIL ; // one more check for spam robot
  470. $body = trim(phpfmg_auto_response_message());
  471. if( empty($body) ){
  472. return false ;
  473. };
  474. $subject = PHPFMG_RETURN_SUBJECT;
  475. $isHtml = 'html' == PHPFMG_MAIL_TYPE ;
  476. $body = phpfmg_adjust_template($body);
  477. $body = phpfmg_parse_mail_body($body,$fields);
  478. $subject = phpfmg_parse_mail_body( $subject, $fields );
  479. if( $isHtml ) {
  480. $body = phpfmg_getHtmlContent( $body );
  481. };
  482. $body = str_replace( "0x0d", '', $body );
  483. $body = str_replace( "0x0a", PHPFMG_LNCR, $body );
  484. return mailAttachments( $to , $subject , $body, filterEmail($from), '' , '', PHPFMG_CHARSET, 'AutoResponseEmail' ) ;
  485. }
  486. function phpfmg_log_mail( $to='', $subject='', $body='', $headers = '', $type='' ){
  487. $sep = str_repeat('----',20) . "\r\n" ;
  488. appendToFile( PHPFMG_EMAILS_LOGFILE, date("Y-m-d H:i:s") . "\t" . $_SERVER['REMOTE_ADDR'] . "\t{$type}\r\n" . $sep . "To: {$to}\r\nSubject: {$subject}\r\n" . $headers . $body . "\r\n" . $sep ) ;
  489. }
  490. function phpfmg_getHtmlContent( $body ){
  491. $html = "
  492. <html>
  493. <title>Your Form Mail Content | htttp://smvdu.net.in/osumclub</title>
  494. <style type='text/css'>
  495. body, td{
  496. font-family : Verdana, Arial, Helvetica, sans-serif;
  497. font-size : 13px;
  498. }
  499. </style>
  500. <body>
  501. "
  502. . $body .
  503. "
  504. </body>
  505. </html>
  506. ";
  507. return $html ;
  508. }
  509. function phpfmg_adjust_template( $body ){
  510. $isHtml = 'html' == PHPFMG_MAIL_TYPE ;
  511. if( $isHtml ){
  512. $body = preg_match( "/<[^<>]+>/", $body ) ? $body : nl2br($body);
  513. };
  514. return $body;
  515. }
  516. function phpfmg_parse_mail_body( $body, $fields = false ){
  517. if( !is_array($fields) )
  518. return $body ;
  519. $yes = function_exists( 'str_ireplace' );
  520. foreach( $fields as $name => $value ){
  521. $body = $yes ? str_ireplace( $name, $value ,$body )
  522. : str_replace ( $name, $value ,$body );
  523. };
  524. return trim($body);
  525. }
  526. # filter line breaks to avoid emails injecting
  527. function filterEmail($email, $chars = ''){
  528. $email = trim(str_replace( array("\r","\n"), '', $email ));
  529. if( is_array($chars) ) $email = str_replace( $chars, '', $email );
  530. return $email;
  531. }
  532. function mailReport( $content = "", $file = '' ){
  533. $content = "
  534. Dear Sir or Madam,
  535. Your online form at " . HOST_NAME . PHP_SELF . " failed to save data to file. Please make sure the web user has permission to write to file \"{$file}\". If you don't know how to fix it, please forward this email to technical support team of your web hosting company or your Administrator.
  536. Shri Mata Vaishno Devi University
  537. - Web Admin SMVDU
  538. ";
  539. mail(PHPFMG_TO, "Error@" . HOST_NAME . PHP_SELF, $content );
  540. }
  541. function remove_newline( $str = "" ){
  542. return str_replace( array("\r\n", "\r", "\n"), array('\r\n', '\r', '\n'), $str );
  543. }
  544. function checkPass( $form_mail = array() )
  545. {
  546. $names = array();
  547. $labels = array();
  548. foreach( $form_mail as $field ){
  549. $type = strtolower( $field[ "type" ] );
  550. $value = trim( $_POST[ $field[ "name" ] ] );
  551. $required = strtolower($field[ "required" ]) ;
  552. $text = stripslashes( $field[ "text" ] );
  553. // simple check the field has something keyed in.
  554. if( !strlen($value) && ( $required == "required" ) && $type != "attachment" ){
  555. $names[] = $field[ "name" ];
  556. $labels[] = $text;
  557. //return ERR_MISSING . $text ;
  558. continue;
  559. };
  560. // verify the special case
  561. if(
  562. ( strlen($value) || $type == "attachment" )
  563. && $required == "Required"
  564. ):
  565. switch( $type ){
  566. case strtolower("Sender's Name") :
  567. break;
  568. case strtolower("Generic email"):
  569. case strtolower("Sender's email"):
  570. if( ! formIsEMail($value) ) {
  571. $names[] = $field[ "name" ];
  572. $labels[] = $text . ERR_EMAIL;
  573. //return ERR_EMAIL . $text ;
  574. };
  575. break;
  576. case "text" :
  577. break;
  578. case "textarea" :
  579. break;
  580. case "checkbox" :
  581. case "radio" :
  582. break;
  583. case "select" :
  584. break;
  585. case "attachment" :
  586. $upload_file = $_FILES[ $field["name"] ][ "tmp_name" ] ;
  587. if( ! is_uploaded_file($upload_file) ){
  588. $names[] = $field[ "name" ];
  589. $labels[] = $text;
  590. //return ERR_SELECT_UPLOAD . $text;
  591. };
  592. break;
  593. case strtolower("Date(MM-DD-YYYY)"):
  594. break;
  595. case strtolower("Date(MM-YYYY)"):
  596. break;
  597. case strtolower("CreditCard(MM-YYYY)"):
  598. if( $value < date("Y-m") ) {
  599. $names[] = $field[ "name" ];
  600. $labels[] = $text;
  601. //return ERR_CREDIT_CARD_EXPIRED . $text;
  602. };
  603. break;
  604. case strtolower("CreditCard#"):
  605. if( !formIsCreditNumber( $value ) ) {
  606. $names[] = $field[ "name" ];
  607. $labels[] = $text;
  608. //return ERR_CREDIT_CARD_NUMBER . $text ;
  609. };
  610. break;
  611. case strtolower("Time(HH:MM:SS)"):
  612. break;
  613. case strtolower("Time(HH:MM)"):
  614. break;
  615. default :
  616. //return $sErrRequired . $form_mail[ $i ][ "text" ];
  617. }; // switch
  618. endif;
  619. }; // for
  620. return array(
  621. 'fields' => $names,
  622. 'errors' => $labels,
  623. );
  624. }
  625. function formSelected( $var, $val )
  626. {
  627. echo ( $var == $val ) ? "selected" : "";
  628. }
  629. function formChecked( $var, $val )
  630. {
  631. echo ( $var == $val ) ? "checked" : "";
  632. }
  633. function formIsEMail( $email ){
  634. return ereg( "^(.+)@(.+)\\.(.+)$", $email );
  635. }
  636. function selectList( $name, $selectedValue, $start, $end, $prompt = "-Select-", $style = "" )
  637. {
  638. $tab = "\t" ;
  639. print "<select name=\"$name\" $style>\n" ;
  640. print $tab . "<option value=''>$prompt</option>\n" ;
  641. $nLen = strlen( "$end" ) ;
  642. $prefix_zero = str_repeat( "0", $nLen );
  643. for( $i = $start; $i <= $end ; $i ++ ){
  644. $stri = substr( $prefix_zero . $i, strlen($prefix_zero . $i)-$nLen, $nLen );
  645. $selected = ( $stri == $selectedValue ) ? " selected " : "" ;
  646. print $tab . "<option value=\"$stri\" $selected >$stri</option>\n" ;
  647. }
  648. print "</select>\n\n" ;
  649. }
  650. # something like CreditCard.pm in perl CPAN
  651. function formIsCreditNumber( $number ) {
  652. $tmp = $number;
  653. $number = preg_replace( "/[^0-9]/", "", $tmp );
  654. if ( preg_match( "/[^\d\s]/", $number ) ) return 0;
  655. if ( strlen($number) < 13 && 0+$number ) return 0;
  656. for ($i = 0; $i < strlen($number) - 1; $i++) {
  657. $weight = substr($number, -1 * ($i + 2), 1) * (2 - ($i % 2));
  658. $sum += (($weight < 10) ? $weight : ($weight - 9));
  659. }
  660. if ( substr($number, -1) == (10 - $sum % 10) % 10 ) return $number;
  661. return $number;
  662. }
  663. /* ---------------------------------------------------------------------------------------------------
  664. Parameters: $sFileName
  665. Return :
  666. 1. "" : no extendsion name, or sFileName is empty
  667. 2. string: MIME Type name of array aMimeType's definition.
  668. ---------------------------------------------------------------------------------------------------*/
  669. function getMIMEType( $sFileName = "" ) {
  670. $sFileName = strtolower( trim( $sFileName ) );
  671. if( ! strlen( $sFileName ) ) return "";
  672. $aMimeType = array(
  673. "txt" => "text/plain" ,
  674. "pdf" => "application/pdf" ,
  675. "zip" => "application/x-compressed" ,
  676. "html" => "text/html" ,
  677. "htm" => "text/html" ,
  678. "avi" => "video/avi" ,
  679. "mpg" => "video/mpeg " ,
  680. "wav" => "audio/wav" ,
  681. "jpg" => "image/jpeg " ,
  682. "gif" => "image/gif" ,
  683. "tif" => "image/tiff " ,
  684. "png" => "image/x-png" ,
  685. "bmp" => "image/bmp"
  686. );
  687. $aFile = split( "\.", basename( $sFileName ) ) ;
  688. $nDiminson = count( $aFile ) ;
  689. $sExt = $aFile[ $nDiminson - 1 ] ; // get last part: like ".tar.zip", return "zip"
  690. return ( $nDiminson > 1 ) ? $aMimeType[ $sExt ] : "";
  691. }
  692. function appendToFile( $sFileName = "", $line = "", $dataColumnsLine = '' ){
  693. if( !$sFileName || !$line ) return 0;
  694. $isExists = file_exists( $sFileName );
  695. $hFile = @fopen( "$sFileName", "a+w" );
  696. $nBytes = 0;
  697. if( $hFile ){
  698. if( !$isExists && false !== strpos(strtolower(basename($sFileName)), '.php') ){
  699. fputs( $hFile, "<?php exit(); /* For security reason. To avoid public user downloading below data! */?>\r\n");
  700. if( !empty($dataColumnsLine) ){
  701. fputs($hFile,$dataColumnsLine."\r\n");
  702. };
  703. };
  704. $nBytes = fputs( $hFile , trim($line)."\r\n" );
  705. fclose( $hFile );
  706. };
  707. return $nBytes ;
  708. }
  709. function phpfmg_get_csv_header($form_mail){
  710. global $form_mail;
  711. $csvValues = array();
  712. foreach( $form_mail as $field ){
  713. $csvValues[] = csvfield( $field[ "text" ] );
  714. };
  715. return join(chr(0x09),/*","*/$csvValues) ;
  716. }
  717. /*
  718. function phpfmg_field_instruction($name, $show = true ){
  719. global $form_mail, $sErr;
  720. $isError = in_array($name,$sErr['fields']);
  721. $class = $isError ? 'instruction_error' : 'instruction' ;
  722. if( $show || $isError ) echo "<div class='{$class}'>". htmlspecialchars_decode($form_mail[ $name ]['instruction']) . "</div>";
  723. }
  724. */
  725. function phpfmg_rand( $len = 4 ){
  726. $md5 = md5( uniqid(rand()) );
  727. return $len > 0 ? substr($md5,0,$len) : $md5 ;
  728. }
  729. function phpfmg_check_captcha(){
  730. $errmsg = '';
  731. if( phpfmg_is_reCAPTCHA() ){
  732. $resp = recaptcha_check_answer (reCAPTCHA_PRIVATE_KEY,
  733. $_SERVER["REMOTE_ADDR"],
  734. $_POST["recaptcha_challenge_field"],
  735. $_POST["recaptcha_response_field"]);
  736. $errmsg = $resp->is_valid ? '' : $resp->error ;
  737. }else{
  738. if( isset($_SESSION[PHPFMG_ID.'fmgCaptchCode']) && strtoupper($_POST['fmgCaptchCode']) != strtoupper($_SESSION[PHPFMG_ID.'fmgCaptchCode']) ){
  739. $errmsg = ERR_CAPTCHA ;
  740. };
  741. };
  742. return $errmsg ;
  743. }
  744. function phpfmg_is_reCAPTCHA(){
  745. return defined('reCAPTCHA_PUBLIC_KEY') && defined('reCAPTCHA_PRIVATE_KEY') && function_exists ("mcrypt_encrypt") && is_file( PHPFMG_ROOT_DIR.'/recaptchalib.php' ) ;
  746. }
  747. function phpfmg_show_captcha(){
  748. if( phpfmg_is_reCAPTCHA() ){
  749. echo recaptcha_get_html(reCAPTCHA_PUBLIC_KEY);
  750. return ;
  751. };
  752. $url = PHPFMG_ADMIN_URL . '?mod=captcha&amp;func=get&amp;tid=' ;
  753. ?>
  754. <img id="phpfmg_captcha_image" src="<?php echo $url . time();?>" onClick="this.src='<?php echo $url ;?>'+Math.random();" border=0 style="cursor:pointer;" alt="Click the image to reload.">
  755. <a href="http://smvdu.net.in" onClick="document.getElementById('phpfmg_captcha_image').src='<?php echo $url ;?>'+Math.random();return false;" style="color:#474747;" title="Reload Security Image" >Reload Image</a><br>
  756. <input type='text' name="fmgCaptchCode" value="" class="fmgCaptchCode" style="width:73px;" >
  757. <?php
  758. }
  759. function phpfmg_hsc($field){
  760. echo HtmlSpecialChars( $_POST[ $field ] );
  761. }
  762. function phpfmg_dropdown( $name, $options, $extra = '', $isReturn = false ){
  763. $dropdown = array();
  764. $list = explode( '|', $options );
  765. $dropdown[] = "<select name='{$name}' class='text_select' {$extra} >";
  766. //$dropdown[] = "<option value='' >{$select}</option>";
  767. if( is_array($list) ){
  768. foreach( $list as $opt ){
  769. $o = phpfmg_parse_option( $opt );
  770. if( isset($_POST['formmail_submit']) ){
  771. $selected = $o['value'] == $_POST[ $name ] ? 'selected' : '' ;
  772. }else{
  773. $selected = $o['default'] ? 'selected' : '' ;
  774. };
  775. $dropdown[] = "<option value=\"{$o['value']}\" {$selected}>{$o['text']}</option>";
  776. };
  777. };
  778. $dropdown[] = "</select>\n";
  779. $s = join("\t\n",$dropdown);
  780. if( $isReturn )
  781. return $s;
  782. else
  783. echo $s ;
  784. }
  785. function phpfmg_dependent_dropdown( $field_name ){
  786. $field = phpfmg_dependent_dropdown_get_field( $field_name );
  787. $dd = new DependantDropdown();
  788. $dd->parseFmgField($field);
  789. $html = $dd->getHtml();
  790. echo $html;
  791. }
  792. function phpfmg_dependent_dropdown_dynamic_require( $field_name ){
  793. $field = phpfmg_dependent_dropdown_get_field( $field_name );
  794. $dd = new DependantDropdown();
  795. $dd->parseFmgField($field);
  796. $dd->dynamicRequired();
  797. }
  798. function phpfmg_dependent_dropdown_get_field( $field_name ){
  799. if( !isset($_SESSION[PHPFMG_ID]) ){
  800. $_SESSION[PHPFMG_ID] = array();
  801. };
  802. if( !isset($_SESSION[PHPFMG_ID]['DD_DATA_' . $field_name]) ){
  803. $base64 = phpfmg_dependent_dropdown_data();
  804. $data = @unserialize( base64_decode($base64) );
  805. $_SESSION[PHPFMG_ID]['DD_DATA_' . $field_name] = $data;
  806. }else{
  807. $data = $_SESSION[PHPFMG_ID]['DD_DATA_' . $field_name];
  808. };
  809. if( !is_array($data) ){
  810. return ;
  811. };
  812. foreach( $data as $field ){
  813. if( $field['name'] == $field_name ){
  814. return $field;
  815. };
  816. };
  817. }
  818. # ------------------------------------------------------
  819. class DependantDropdown
  820. {
  821. var $data = '';
  822. var $sheet = array();
  823. var $fields = array();
  824. var $fieldInfo = array( 'label', 'instruction', 'required', 'prompt' ); // describe field information from the first N rows of data
  825. var $prefix = 'dd'; // in case there is no name for dropdown, it will name the dropdown like dd_0, dd_1, ...
  826. var $fmgField = false;
  827. var $newliner = "<!--esh_newline-->" ; // replace \r\n with $newliner ;
  828. var $newtaber = "<!--esh_newtaber-->" ; // replace \t with $newtaber ;
  829. function DependantDropdown(){
  830. }
  831. function lookupFieldColumn( $field, $column, $lookup, $contentType='text/plain', $charset='utf-8' ){
  832. $this->parseFmgField( $field );
  833. $this->nocache_headers( $contentType, $charset );
  834. return join( "\n", $this->getColumn( $column, $lookup ) );
  835. }
  836. function parseFmgField( $field ){
  837. if( !isset($_SESSION[PHPFMG_ID]) ){
  838. $_SESSION[PHPFMG_ID] = array();
  839. };
  840. $this->fmgField = $field;
  841. $value = $this->newline_back($field['value']);
  842. $this->data = explode("\r\n",$value);
  843. if( !isset($_SESSION[PHPFMG_ID][ "DD_".$field['name'] ]) ){
  844. $this->parseData($field);
  845. $_SESSION[PHPFMG_ID][ "DD_".$field['name'] ] = $this->fields;
  846. }else{
  847. $this->fields = $_SESSION[PHPFMG_ID][ "DD_".$field['name'] ];
  848. };
  849. $this->makeupFieldsName();
  850. }
  851. function newline_back( $str = "" ){
  852. return str_replace( array($this->newtaber, $this->newliner), array("\t","\r\n"), $str );
  853. }
  854. function nocache_headers($contentType='text/plain', $charset='utf-8'){
  855. header("Expires: Mon, 01 Jan 1970 00:00:01 GMT");
  856. header("Cache-Control: max-age=0, no-store, no-cache, must-revalidate");
  857. header("Cache-Control: post-check=0, pre-check=0", false);
  858. header("Pragma: no-cache");
  859. header( "Content-Type: {$contentType}; charset={$charset}" );
  860. }
  861. function setData( $s ){
  862. $this->data = $s ;
  863. }
  864. function setPrefix( $s ){
  865. $this->prefix = $s;
  866. }
  867. function parseData(){
  868. $tab = chr(0x09);
  869. $nFieldInfoRows = count( $this->fieldInfo );
  870. for( $i = 0, $n = count($this->data); $i < $n; $i ++ ){
  871. $line = str_replace('"', '', $this->data[$i] );
  872. $cols = explode( $tab, $line );
  873. if( is_array($cols) && count($cols) > 1 ){
  874. if( $i < $nFieldInfoRows ){
  875. $trims = array();
  876. foreach( $cols as $col ){
  877. $trims[] = trim($col);
  878. };
  879. $this->fields[ $this->fieldInfo[$i] ] = $trims;
  880. }
  881. else
  882. $this->fields['data'][] = $cols;
  883. }; // if
  884. //if ( $i > 1000 ) break;
  885. }; // for
  886. }
  887. // $quickTest : to see whether a column contains data
  888. function getColumn( $n, $lookup = array(), $quickTest = false ){
  889. $count = count($lookup);
  890. if( $n > 0 && empty($count) ){
  891. return array(); // can not get column without search query
  892. };
  893. $col = array();
  894. $lastValue = $lookup[ $count - 1 ];
  895. $flatLookup = join( '|', $lookup );
  896. foreach( $this->fields['data'] as $r ){
  897. if( !isset($r[$n]) )
  898. continue;
  899. $value = trim($r[$n]);
  900. if( $value == '' )
  901. continue;
  902. //$value = $r[$n];
  903. if( $n == 0 ){
  904. $col[] = $value;
  905. }else{
  906. //if( trim($r[$n-1]) == $lastValue ){ // quick check to improve performance
  907. if( $r[$n-1] == $lastValue ){ // quick check the last value to improve performance
  908. $leftCols = array_slice( $r, 0, $n );
  909. $flatLeftValues = join( '|', $leftCols );
  910. if( $flatLeftValues == $flatLookup ){ // show value only by lookuping by joining all its parents' values
  911. $col[] = $value;
  912. };
  913. }; // if
  914. }; // if $n == 0
  915. if( $quickTest && count($col) > 0 ) break;
  916. }; // foreach
  917. return array_unique($col);
  918. }
  919. function getColumnOptions( $n, $lookup = array(), $default = '' ){
  920. $opts = array();
  921. foreach( $this->getColumn($n, $lookup) as $v ){
  922. $selected = $default == $v ? 'selected' : '' ;
  923. $opts[] = "<option {$selected} value=\"" . htmlspecialchars($v) . "\">{$v}</option>";
  924. };
  925. return join("\n",$opts);
  926. }
  927. function getHtml(){
  928. $html = array();
  929. $field_name = $this->fmgField['name'];
  930. $this->prefix = $field_name;
  931. $count = count($this->fields['label']);
  932. // prepare for getting column options after form submitted
  933. $lookup = array();
  934. $isPost = isset($_POST[ $this->fields['name'][0] ]);
  935. if( $isPost ){
  936. for( $i = 0; $i < $count; $i++ ){
  937. $label = $this->fields['label'][$i];
  938. if( empty($label) )
  939. continue;
  940. $lookup[] = $_POST[ $this->fields['name'][$i] ];
  941. };
  942. };
  943. for( $i = 0; $i < $count; $i++ ){
  944. $label = $this->fields['label'][$i];
  945. if( empty($label) )
  946. continue;
  947. $name = $this->fields['name'][$i];
  948. $instruction = $this->fields['instruction'][$i];
  949. $prompt = $this->fields['prompt'][$i];
  950. $required = $this->fields['required'][$i];
  951. $promptOption = empty($prompt) ? "" : "<option value=''>{$prompt}</option>";
  952. if( $isPost )
  953. $options = $this->getColumnOptions( $i, array_slice($lookup,0,$i), $_POST[$name] );
  954. else
  955. $options = $this->getColumnOptions( $i, array(), '' );
  956. $select = "<select id='{$name}' class='text_select' name='{$name}' onchange=\"dd_change({$i}, {$count}, '{$this->prefix}');\">{$promptOption}" . $options . "</select>";
  957. $sRequired = "<label class='form_required' >" . (strtolower($required) == 'required'? '*' : '&nbsp;') . "</label>" ;
  958. $li = "
  959. <li class='field_block' id='{$name}_div'>
  960. <div class='col_label'>
  961. <label class='form_field'>{$label}</label>{$sRequired}
  962. </div>
  963. <div class='col_field'>
  964. {$select}
  965. <div id='{$name}_tip' class='instruction'>{$instruction}</div>
  966. </div>
  967. </li>
  968. ";
  969. $html[] = $li;
  970. };
  971. echo join("\n\n",$html);
  972. }
  973. function dynamicRequired(){
  974. if( !isset($_POST) ){
  975. return ;
  976. };
  977. global $form_mail;
  978. $field_name = $this->fmgField['name'];
  979. $this->prefix = $field_name;
  980. $count = count($this->fields['label']);
  981. $lookup = array();
  982. $isPost = isset($_POST[ $this->fields['name'][0] ]);
  983. if( $isPost ){
  984. for( $i = 0; $i < $count; $i++ ){
  985. $label = $this->fields['label'][$i];
  986. if( empty($label) )
  987. continue;
  988. $lookup[] = $_POST[ $this->fields['name'][$i] ];
  989. };
  990. };
  991. for( $i = 0; $i < $count; $i++ ){
  992. $label = $this->fields['label'][$i];
  993. if( empty($label) )
  994. continue;
  995. $name = $this->fields['name'][$i];
  996. $required = $this->fields['required'][$i];
  997. if( strtolower($required) == 'required' ){
  998. $rows = $this->getColumn( $i, array_slice($lookup,0,$i), true );
  999. if( empty($rows) ) {
  1000. $form_mail[ $name ]['required'] = '' ; //
  1001. };
  1002. }else{
  1003. $form_mail[ $name ]['required'] = '' ;
  1004. };
  1005. };
  1006. }
  1007. function getFormMailArrayCode(){
  1008. $code = array();
  1009. for( $i = 0, $n = count($this->fields['label']); $i < $n; $i++ ){
  1010. $label = $this->fields['label'][$i];
  1011. if( empty($label) )
  1012. continue;
  1013. $name = $this->fields['name'][$i];
  1014. $instruction = $this->fields['instruction'][$i];
  1015. $prompt = $this->fields['prompt'][$i];
  1016. $required = $this->fields['required'][$i];
  1017. $code[] = "\$form_mail['{$name}'] = array( \"name\" => \"$name\", \"text\" => \"" . addslashes( $label ) . "\", \"type\" => \"select\", \"instruction\" => \"$instruction\", \"required\" => \"$required\" ) ;" ;
  1018. };
  1019. return join("\n",$code);
  1020. }
  1021. function makeupFieldsName($default='field_99'){
  1022. $field_name = isset($this->fmgField['name']) ? $this->fmgField['name'] : $default;
  1023. $this->prefix = $field_name;
  1024. for( $i = 0, $n = count($this->fields['label']); $i < $n; $i++ ){
  1025. $this->fields['name'][$i] = $this->prefix . '_' . $i;
  1026. };
  1027. }
  1028. }
  1029. function phpfmg_parse_option( $opt ){
  1030. $opt = $opt;
  1031. $a = array(
  1032. 'text' => $opt,
  1033. 'value' => $opt,
  1034. 'default' => false,
  1035. );
  1036. $pos = strrpos( $opt, '=' );
  1037. if( false !== $pos ){
  1038. $a['text'] = substr($opt,0,$pos);
  1039. $part = substr($opt,$pos+1);
  1040. $nv = strrpos( $part, ',' );
  1041. if( false !== $nv ){
  1042. $a['value'] = substr($part,0,$nv);
  1043. $a['default'] = 'default' == strtolower(substr($part,$nv+1));
  1044. }else{
  1045. $a['value'] = $part;
  1046. };
  1047. };
  1048. $a['text'] = trim($a['text']);
  1049. $a['value'] = trim($a['value']);
  1050. return $a ;
  1051. }
  1052. function phpfmg_choice( $type, $name, $options, $isReturn = false ){
  1053. $radios = array();
  1054. $list = explode( '|', $options );
  1055. if( is_array($list) ){
  1056. $i = 0 ;
  1057. foreach( $list as $opt ){
  1058. //$value = HtmlSpecialChars( $opt );
  1059. $o = phpfmg_parse_option( $opt );
  1060. $id = "{$name}_{$i}";
  1061. $newname = 'checkbox' == $type ? "Checkbox" . substr("00".($i+1), strlen("00".($i+1))-2,2) . "_" . $name : $name;
  1062. if( isset($_POST['formmail_submit']) ){
  1063. $checked = $o['value'] == $_POST[ $newname ] ? 'checked' : '' ;
  1064. }else{
  1065. $checked = $o['default'] ? 'checked' : '' ;
  1066. };
  1067. //$radios[] = "<input type='{$type}' name='{$newname}' id='{$id}' value=\"{$o['value']}\" {$checked} class='form_{$type}' ><label class='form_{$type}_text' onclick=\"fmgHandler.choice_clicked('{$id}');\" onmouseover=\"this.className='form_{$type}_text form_choice_over';\" onmouseout=\"this.className='form_{$type}_text form_choice_out';\">{$o['text']}</label><br />";
  1068. $labelLeft = ''; //0 == $i ? '' : "<div class='form_field'>&nbsp;</div><div class='choice'>&nbsp;</div>" ; // spacer for text algin left
  1069. $radios[] = "{$labelLeft}<input type='{$type}' name='{$newname}' id='{$id}' value=\"{$o['value']}\" {$checked} class='form_{$type}' ><label class='form_choice_text' for='{$id}'>{$o['text']}</label><br>";
  1070. $i ++ ;
  1071. };
  1072. };
  1073. $s = join("\t\n",$radios);
  1074. //$s = "<div class='choices'>$s</div>";
  1075. if( $isReturn )
  1076. return $s;
  1077. else
  1078. echo $s ;
  1079. }
  1080. function phpfmg_radios( $name, $options, $isReturn = false ){
  1081. return phpfmg_choice( 'radio', $name, $options, $isReturn );
  1082. }
  1083. function phpfmg_checkboxes( $name, $options, $isReturn = false ){
  1084. return phpfmg_choice( 'checkbox', $name, $options, $isReturn );
  1085. }
  1086. function phpfmg_rename_harmful( $name ){
  1087. //if( defined('PHPFMG_BLOCK_HARMFUL') && 'Y' == PHPFMG_BLOCK_HARMFUL ){
  1088. $ext = strrchr(strtolower($name), '.');
  1089. if( $ext !== false ){
  1090. $n = strpos( strtolower(PHPFMG_HARMFUL_EXTS), $ext );
  1091. if( $n !== false ){
  1092. return $name . '.bak' ;
  1093. };
  1094. };
  1095. //};
  1096. return $name;
  1097. }
  1098. function phpfmg_redirect_js(){
  1099. if( defined('PHPFMG_REDIRECT') && '' != PHPFMG_REDIRECT ){
  1100. echo "<script type='text/javascript'>
  1101. function phpfmg_redirect(){
  1102. var redirect = '" . addslashes(PHPFMG_REDIRECT) . "';
  1103. try{
  1104. if( parent ) parent.location.href = redirect;
  1105. }catch(e){
  1106. location.href = redirect;
  1107. };
  1108. }
  1109. phpfmg_redirect();
  1110. </script>";
  1111. };
  1112. }
  1113. if (!function_exists("htmlspecialchars_decode")) {
  1114. function htmlspecialchars_decode($string, $quote_style = ENT_COMPAT) {
  1115. return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS, $quote_style)));
  1116. }
  1117. }
  1118. function phpfmg_text_align(){
  1119. $align = strtolower(defined('PHPFMG_TEXT_ALIGN') ? PHPFMG_TEXT_ALIGN : 'top');
  1120. switch( $align ){
  1121. case 'left' :
  1122. case 'right' :
  1123. $labelWidth = '158px';
  1124. if( false !== strpos( strtolower($_SERVER['HTTP_USER_AGENT']), 'msie') ){
  1125. # ----------- for IE -------
  1126. $css = "
  1127. ol.phpfmg_form{
  1128. width: 468px;
  1129. }
  1130. div.col_field, div.col_label{
  1131. display:inline;
  1132. float:left;
  1133. }
  1134. div.col_label{
  1135. width:{$labelWidth};
  1136. text-align: {$align};
  1137. }
  1138. ";
  1139. }else{
  1140. # ----------- for Firefox -------
  1141. $css = "
  1142. div.col_label{
  1143. float:left;
  1144. width:{$labelWidth};
  1145. text-align: {$align};
  1146. }
  1147. div.col_field{ margin-left:{$labelWidth}; }
  1148. ";
  1149. }; // if
  1150. break;

Large files files are truncated, but you can click here to view the full file