Source for file profile.php

Documentation is available at profile.php

  1. <?php //-*-php-*-
  2. /* ******************************************************************** **
  3. ** Copyright notice **
  4. ** **
  5. ** (c) 1995-2003 PHPOpenChat Development Team **
  6. ** http://phpopenchat.sourceforge.net/ **
  7. ** **
  8. ** All rights reserved **
  9. ** **
  10. ** This script is part of the PHPOpenChat project. The PHPOpenChat **
  11. ** project is free software; you can redistribute it and/or modify **
  12. ** it under the terms of the GNU General Public License as published by **
  13. ** the Free Software Foundation; either version 2 of the License, or **
  14. ** (at your option) any later version. **
  15. ** **
  16. ** The GNU General Public License can be found at **
  17. ** http://www.gnu.org/copyleft/gpl.html. **
  18. ** A copy is found in the textfile GPL and important notices to the **
  19. ** license from the team is found in the textfile LICENSE distributed **
  20. ** with these scripts. **
  21. ** **
  22. ** This script is distributed in the hope that it will be useful, **
  23. ** but WITHOUT ANY WARRANTY; without even the implied warranty of **
  24. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
  25. ** GNU General Public License for more details. **
  26. ** **
  27. ** This copyright notice MUST APPEAR in all copies of the script! **
  28. ** ******************************************************************** */
  29.  
  30. /*
  31. $Author: letreo $
  32. $Date: 2003/08/07 21:20:23 $
  33. $Source: /cvsroot/phpopenchat/chat3/profile.php,v $
  34. $Revision: 1.23 $
  35. */
  36.  
  37. //Get default values
  38. require_once('config.inc.php');
  39.  
  40. require_once(POC_INCLUDE_PATH.'/adodb/adodb.inc.php');
  41. require_once(POC_INCLUDE_PATH.'/class.Chat.inc');
  42. require_once(POC_INCLUDE_PATH.'/class.Chatter.inc');
  43. require_once(POC_INCLUDE_PATH.'/class.Translator.inc');
  44. require_once(POC_INCLUDE_PATH.'/class.Template.inc');
  45. require_once(POC_INCLUDE_PATH.'/class.UploadFile.inc');
  46.  
  47. session_start();
  48.  
  49. //check if chatter is authorized to get this page
  50. if( !isset($_SESSION['chatter']) )
  51. die('Login first!');
  52. $_SESSION['reload_count'] = 0;
  53. if( $_SESSION['chatter']->is_guest() )
  54. die($_SESSION['translator']->out('DENIED_FOR_GUESTS'));
  55.  
  56. function upload_image( $dir, $image_type ){
  57. global $ACCEPTED_MIME_TYPES;
  58. $uploader = &new UploadFile( $_FILES['chatter_'.$image_type], $image_type );
  59. $uploader->set_types( $ACCEPTED_MIME_TYPES );//defined in config.inc.php
  60. //$uploader->set_upload_path( $_SESSION['template']->get_tmpl_sys_path().'/images/icons/chatter/' );
  61. $uploader->set_upload_path( $_SESSION['template']->get_tmpl_sys_path().'/images'.$dir.'/' );
  62. $upload_errors = array();
  63. if( !$uploader->check() ) {
  64. $upload_errors = $uploader->get_errors();
  65. } else {
  66. if(!$uploader->upload( constant('PRIVATE_'.strtoupper($image_type).'_SAVE_MODE') )) {
  67. $upload_errors = $uploader->get_errors();
  68. if(isset($upload_errors[0]))
  69. print $upload_errors[0];
  70. die('Unable to create file: Permission denied<br>Check write permissions of your web server in: '.$uploader->get_upload_path() );
  71. }
  72. }
  73. $file_upload_errors = '';
  74. if( count($upload_errors) > 0 ) {
  75. $file_upload_errors = '<menu class="uploadErrors">'.NL;
  76. reset($upload_errors);
  77. do {
  78. $file_upload_errors .= TAB.'<li>'.current($upload_errors).'</li>'.NL;
  79. } while(next($upload_errors));
  80. $file_upload_errors .= '</menu>'.NL;
  81. }
  82. return $file_upload_errors;
  83. }
  84. $errors = array();
  85. $update_status = '';
  86.  
  87. $_SESSION['chatter']->init_additional_profile_data();
  88. function analyze_post_data() {
  89. global $errors;
  90.  
  91. //password
  92. if( !isset($_POST['password'])
  93. || $_POST['password'] == ''
  94. || !$_SESSION['chatter']->set_password( $_POST['password'] ) )
  95. $errors['password'] = $_SESSION['translator']->out('ERROR_PASSWORD');
  96.  
  97. //user name
  98. if( !isset($_POST['name'])
  99. || !$_SESSION['chatter']->set_name( $_POST['name'] )
  100. || $_POST['name'] == '' )
  101. $errors['name'] = $_SESSION['translator']->out('ERROR_NAME');
  102.  
  103. //birthday
  104. if( !$_SESSION['chatter']->set_birthday($_POST['birthyear'].'-'.$_POST['birthmonth'].'-'.$_POST['birthday']) )
  105. $errors['birthday'] = $_SESSION['translator']->out('ERROR_BIRTHDAY');
  106.  
  107. //email
  108. if( !isset($_POST['email'])
  109. || $_POST['email'] == ''
  110. || !$_SESSION['chatter']->set_email( $_POST['email'] ) )
  111. $errors['email'] = $_SESSION['translator']->out('ERROR_EMAIL');
  112.  
  113. //hide email?
  114. $bool = ($_POST['hideEmail']==1)? true:false;
  115. $_SESSION['chatter']->set_hide('email',$bool);
  116. //gender
  117. $_SESSION['chatter']->set_gender( $_POST['gender'] );
  118. //pictureURL
  119. if( !isset($_POST['pictureURL'])
  120. || !$_SESSION['chatter']->set_pictureURL( $_POST['pictureURL'] ) )
  121. $errors['pictureURL'] = $_SESSION['translator']->out('ERROR_PICTURE_URL');
  122. //homePageURL
  123. if( !isset($_POST['homePageURL'])
  124. || !$_SESSION['chatter']->set_homePageURL( $_POST['homePageURL'] ) )
  125. $errors['homePageURL'] = $_SESSION['translator']->out('ERROR_HOMEPAGE_URL');
  126. //Interests
  127. if( !$_SESSION['chatter']->set_interests($_POST['interests']) )
  128. $errors['interests'] = $_SESSION['translator']->out('ERROR_INTERESTS');
  129.  
  130. //Motto
  131. if( !$_SESSION['chatter']->set_motto($_POST['motto']) )
  132. $errors['motto'] = $_SESSION['translator']->out('ERROR_MOTTO');
  133.  
  134. //ICQ number
  135. if( !isset($_POST['icqNumber']) || !$_SESSION['chatter']->set_icqNumber($_POST['icqNumber']) )
  136. $errors['icqNumber'] = $_SESSION['translator']->out('ERROR_ICQ_NUMBER');
  137. //AIM nickname
  138. if( !isset($_POST['aimNickname']) || !$_SESSION['chatter']->set_aimNickname($_POST['aimNickname']) )
  139. $errors['aimNickname'] = $_SESSION['translator']->out('ERROR_AIM_NICKNAME');
  140. //YIM nickname
  141. if( !isset($_POST['yimNickname']) || !$_SESSION['chatter']->set_yimNickname($_POST['yimNickname']) )
  142. $errors['yimNickname'] = $_SESSION['translator']->out('ERROR_YIM_NICKNAME');
  143.  
  144. return ( count($errors) == 0);
  145. }
  146.  
  147. if(!isset($_POST['hideEmail'])) $_POST['hideEmail'] = 0;
  148.  
  149. if( isset($_POST['changeProfile']) ) {
  150. if( analyze_post_data() ) {
  151. $update_status = $_SESSION['translator']->out('PROFILE_UPDATA_SUCCESSFUL');
  152. $_SESSION['chatter']->update();
  153. } else {
  154. $update_status = $_SESSION['translator']->out('PROFILE_UPDATA_NOT_SUCCESSFUL');
  155. }
  156. } else {
  157. $day_of_birth = $_SESSION['chatter']->get_birthday();
  158. $parts = split('-',$day_of_birth);
  159. $_POST['birthday'] = $parts[2];
  160. $_POST['birthmonth'] = $parts[1];
  161. $_POST['birthyear'] = $parts[0];
  162. unset($parts);
  163. $_POST['hideEmail'] = ($_SESSION['chatter']->get_hide('email')==true)? '1':'0';
  164. $_POST['gender'] = $_SESSION['chatter']->get_gender();
  165. }
  166. $disableGender = ($_POST['gender']=='')? '':'disabled="disabled"';
  167. $hiddenGender = ($disableGender=='disabled="disabled"')? '<input type="hidden" name="gender" value="'.$_POST['gender'].'"/>'.NL:'';
  168.  
  169. //$file_upload_errors = '';
  170. //$upload_errors = array();
  171.  
  172. $TEMPLATE_OUT['file_upload_errors'] = '';
  173. if( isset($_POST['uploadImage']) && isset($_FILES['chatter_icon']) ) {
  174. $TEMPLATE_OUT['file_upload_errors'] = upload_image( '/icons/chatter', 'icon' );
  175. }
  176. if( isset($_POST['uploadImage']) && isset($_FILES['chatter_image']) ) {
  177. $TEMPLATE_OUT['file_upload_errors'] = upload_image( '/chatter', 'image' );
  178. }
  179. $TEMPLATE_OUT['private_icon'] = Template::get_image_tag('/icons/chatter');
  180. $TEMPLATE_OUT['private_image'] = Template::get_image_tag('/chatter');
  181.  
  182. $year_option_list = '';
  183. $selected='';
  184. $current_year = date('Y', time());
  185. for ($i=MIN_BIRTHDAY_YEAR;$i<=$current_year;$i++) {
  186. if( isset($_POST['birthyear']) && $_POST['birthyear'] == $i ) $selected='selected="selected"';
  187. $year_option_list .= '<option value="'.$i.'" '.$selected.'>'.$i.'</option>';
  188. $selected='';
  189. }
  190.  
  191. $month_option_list = '';
  192. for ($i=1;$i<=12;$i++) {
  193. if( isset($_POST['birthmonth']) && intval($_POST['birthmonth']) == $i ) $selected='selected="selected"';
  194. $month_option_list .= '<option value="'.$i.'" '.$selected.'>'.$i.'</option>';
  195. $selected='';
  196. }
  197.  
  198. $day_option_list = '';
  199. for ($i=1;$i<=31;$i++) {
  200. if( isset($_POST['birthday']) && intval($_POST['birthday']) == $i ) $selected='selected="selected"';
  201. $day_option_list .= '<option value="'.$i.'" '.$selected.'>'.$i.'</option>';
  202. $selected='';
  203. }
  204.  
  205. $genderFemaleSelected = ( $_POST['gender'] == 'f')? 'selected="selected"':'';
  206. $genderMaleSelected = ( $_POST['gender'] == 'm')? 'selected="selected"':'';
  207. $hideEmail_checked = ( $_POST['hideEmail'] == 1 )? 'checked="checked"':'';
  208.  
  209. $TEMPLATE_OUT['update_status'] = $update_status;
  210. $TEMPLATE_OUT['errors'] = $errors;
  211. //$TEMPLATE_OUT['private_image'] = $private_image;
  212. //$TEMPLATE_OUT['file_upload_errors'] = $file_upload_errors;
  213.  
  214. $TEMPLATE_OUT['hiddenGender'] = $hiddenGender;
  215. $TEMPLATE_OUT['disableGender'] = $disableGender;
  216. $TEMPLATE_OUT['genderFemaleSelected'] = $genderFemaleSelected;
  217. $TEMPLATE_OUT['genderMaleSelected'] = $genderMaleSelected;
  218. $TEMPLATE_OUT['day_option_list'] = $day_option_list;
  219. $TEMPLATE_OUT['month_option_list'] = $month_option_list;
  220. $TEMPLATE_OUT['year_option_list'] = $year_option_list;
  221. $TEMPLATE_OUT['hideEmail_checked'] = $hideEmail_checked;
  222.  
  223. $TEMPLATE_OUT['misc_options'] = '<option />';
  224. $misc = array();
  225. $misc = $_SESSION['chatter']->get_profile_misc();
  226. foreach($misc as $key => $value) {
  227. $TEMPLATE_OUT['misc_options'] .= TAB.'<option value="'.$value[0].'">'.$value[0].'</option>'.NL;
  228. }
  229. $_SESSION['template']->get_template();
  230. ?>

Documentation generated on Tue, 29 Jun 2004 14:42:40 +0200 by phpDocumentor 1.3.0RC3