user_fields.php
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:38k
源码类别:

电子政务应用

开发平台:

Java

  1. <?php
  2. // +-------------------------------------------------------------+
  3. // | DeskPRO v [2.0.1 Production]
  4. // | Copyright (C) 2001 - 2004 Headstart Solutions Limited
  5. // | Supplied by WTN-WDYL
  6. // | Nullified by WTN-WDYL
  7. // | Distribution via WebForum, ForumRU and associated file dumps
  8. // +-------------------------------------------------------------+
  9. // | DESKPRO IS NOT FREE SOFTWARE
  10. // +-------------------------------------------------------------+
  11. // | License ID : Full Enterprise License =) ...
  12. // | License Owner : WTN-WDYL Team
  13. // +-------------------------------------------------------------+
  14. // | $RCSfile: user_fields.php,v $
  15. // | $Date: 2004/02/10 01:34:25 $
  16. // | $Revision: 1.31 $
  17. // +-------------------------------------------------------------+
  18. // | File Details:
  19. // | - Custom user field maintenance (administration interface)
  20. // +-------------------------------------------------------------+
  21. error_reporting(E_ALL & ~E_NOTICE);
  22. require_once('./global.php');
  23. //Nullify WTN-WDYL Team
  24. // default do
  25. $_REQUEST['do'] = trim($_REQUEST['do']);
  26. if (!isset($_REQUEST['do']) or $_REQUEST['do'] == "") {
  27. $_REQUEST['do'] = "view";
  28. }
  29. // globalise variables
  30. $global = array (
  31. array('id', 'number'),
  32. array('type')
  33. );
  34. rg($global);
  35. language_check();
  36. ############################### CREATE INDEX ###############################
  37. if ($_REQUEST['do'] == 'createindex') {
  38. $db->query("SHOW INDEX FROM user");
  39. while ($index = $db->row_array()) {
  40. $indexed[$index['Column_name']] = 1;
  41. }
  42. $column = $db->query_return("SELECT name FROM user_def WHERE id = '$_REQUEST[id]'");
  43. $column = $column['name'];
  44. if (!$indexed[$column]) {
  45. $db->query("CREATE INDEX $column ON user ($column(20))");
  46. alert('Index created.');
  47. $_REQUEST['do'] = 'view';
  48. } else {
  49. alert('Index already present.');
  50. }
  51. }
  52. ############################### DELETE INDEX ###############################
  53. if ($_REQUEST['do'] == 'dropindex') {
  54. $db->query("SHOW INDEX FROM user");
  55. while ($index = $db->row_array()) {
  56. $indexed[$index['Column_name']] = 1;
  57. }
  58. $column = $db->query_return("SELECT name FROM user_def WHERE id = '$_REQUEST[id]'");
  59. $column = $column['name'];
  60. if ($indexed[$column]) {
  61. $db->query("DROP INDEX $column ON user");
  62. alert('Index removed.');
  63. $_REQUEST['do'] = 'view';
  64. } else {
  65. alert('No index present.');
  66. }
  67. }
  68. ############################### CREATE NEW PROFILE FIELDS ###############################
  69. if (($_REQUEST['do'] == "new3") OR ($_REQUEST['do'] == "update")) {
  70. if ($_REQUEST['regex'] != NULL) {
  71. $match = @preg_match($_REQUEST['regex'], '');
  72. if (!is_int($match)) { // It's invalid unless $match is an integer
  73. mistake('The regular expression you specified is invalid. Refer to
  74. PHP's manual
  75. for current information about PHP's implementation of Perl-compatible 
  76. Regular Expressions. This may assist you in building a valid regular
  77. expression. Please go back and correct the regular expression.');
  78. }
  79. }
  80. // code for creating a new field
  81. if ($_REQUEST['do'] == "new3") {
  82. $query = "INSERT INTO user_def SET ";
  83. // get max field number
  84. $db->query("SELECT name FROM user_def WHERE name LIKE 'custom%'");
  85. while ($results = $db->row_array()) {
  86. eregi("^custom([0-9]*)", $results[name], $value);
  87. if ($max < $value[1]) {
  88. $max = $value[1];
  89. }
  90. }
  91. $max++;
  92. $name = "custom" . $max;
  93. // create the column
  94. $db->query("ALTER TABLE user ADD $name MEDIUMTEXT");
  95. // sort out field
  96. $user_field[formtype] = $_REQUEST[formtype];
  97. // code for updating a field
  98. } elseif ($_REQUEST['do'] == "update") {
  99. $user_field = $db->query_return("SELECT * FROM user_def WHERE id = " . intval($id));
  100. $query = "UPDATE user_def SET ";
  101. $name = $user_field[name];
  102. }
  103. ############################### THE FIELD DATA ############################### 
  104. if (($user_field[formtype] == "checkbox") OR 
  105. ($user_field[formtype] == "radio") OR 
  106. ($user_field[formtype] == "select")) {
  107. // build array of current data
  108. $temp_data = unserialize($user_field[data]);
  109. if (is_array($temp_data)) {
  110. foreach($temp_data AS $key => $var) {
  111. $with_content[] = $temp_data[$key][0];
  112. }
  113. }
  114. // build array of new data
  115. if (is_array($_REQUEST[elementid])) {
  116. $default = 0;
  117. foreach($_REQUEST[elementid] AS $key => $var) {
  118. if (!is_int($key)) {
  119. $key++;
  120. }
  121. if ($_REQUEST[name][$key] != "") {
  122. if ($user_field[formtype] == "radio" or ($user_field[formtype] == "select" AND !$user_field[multiselect])) {
  123. if ($default) {
  124. $def = 0;
  125. } else {
  126. $def = $_REQUEST[start][$key];
  127. }
  128. } else {
  129. $def = $_REQUEST[start][$key];
  130. }
  131. $data[] = array(
  132. $key,
  133. $_REQUEST[order][$key],
  134. $_REQUEST[name][$key],
  135. $def
  136. );
  137. } else {
  138. // check if there used to be value
  139. if (is_array($with_content)) {
  140. if (in_array($key, $with_content)) {
  141. // row needs to be deleted from the database
  142. $db->query("
  143. UPDATE user SET $user_field[name] = REPLACE ($user_field[name], '$key|||', '')
  144. ");
  145. }
  146. }
  147. }
  148. }
  149. }
  150. // sort based on order
  151. if (is_array($data)) {
  152. usort($data, "array_order2"); 
  153. }
  154. // convert to data to store in database
  155. $data = serialize($data);
  156. }
  157. ############################### LANGUAGE BITS ###############################
  158. if ($settings[language_on]) {
  159. $_REQUEST[display_name] = serialize($_REQUEST[display_name]);
  160. $_REQUEST[description] = serialize($_REQUEST[description]);
  161. $_REQUEST[error_message] = serialize($_REQUEST[error_message]);
  162. } else {
  163. $display_name[$settings[default_language]] = $_REQUEST['display_name'];
  164. $description[$settings[default_language]] = $_REQUEST['description'];
  165. $error_message[$settings[default_language]] = $_REQUEST['error_message'];
  166. $_REQUEST[display_name] = serialize($display_name);
  167. $_REQUEST[description] = serialize($description);
  168. $_REQUEST[error_message] = serialize($error_message);
  169. }
  170. ############################### QUERY REDIRECT ############################### 
  171. $query .= "
  172. name = '$name',
  173. data = '".mysql_escape_string($data)."',
  174. display_name = '".mysql_escape_string($_REQUEST['display_name'])."',
  175. description = '".mysql_escape_string($_REQUEST['description'])."',
  176. required = '".mysql_escape_string($_REQUEST['required'])."',
  177. user_start  = '".mysql_escape_string($_REQUEST['user_start'])."',
  178. user_viewable = '".mysql_escape_string($_REQUEST['user_viewable'])."',
  179. user_editable = '".mysql_escape_string($_REQUEST['user_editable'])."',
  180. tech_viewable = '".mysql_escape_string($_REQUEST['tech_viewable'])."',
  181. tech_editable = '".mysql_escape_string($_REQUEST['tech_editable'])."',
  182. displayorder = '".mysql_escape_string($_REQUEST['displayorder'])."',
  183. extrainput = '".mysql_escape_string($_REQUEST['extrainput'])."',
  184. extrainput_location = '".mysql_escape_string($_REQUEST['extrainput_location'])."',
  185. extrainput_text = '".mysql_escape_string($_REQUEST['extrainput_text'])."',
  186. minlength = '".mysql_escape_string($_REQUEST['minlength'])."',
  187. maxlength = '".mysql_escape_string($_REQUEST['maxlength'])."',
  188. maxoptions = '".mysql_escape_string($_REQUEST['maxoptions'])."',
  189. minoptions = '".mysql_escape_string($_REQUEST['minoptions'])."',
  190. multiselect = '".mysql_escape_string($_REQUEST['multiselect'])."',
  191. height = '".mysql_escape_string($_REQUEST['height'])."',
  192. regex = '".mysql_escape_string($_REQUEST['regex'])."',
  193. perline = '".mysql_escape_string($_REQUEST['perline'])."',
  194. error_message = '".mysql_escape_string($_REQUEST['error_message'])."',
  195. length = '".mysql_escape_string($_REQUEST['length'])."',
  196. formtype = '$user_field[formtype]'
  197. ";
  198. if ($_REQUEST['do'] == "new3") {
  199. $db->query($query);
  200. $id = $db->last_id();
  201. jump("user_fields.php?do=edit&id=$id", 'New field has been created<br />Redirecting you to your new field');
  202. } else {
  203. $db->query($query . "WHERE id = " . intval($id));
  204. jump("user_fields.php?do=edit&id=$id", 'Field has been updated<br />Redirecting you to the updated field');
  205. }
  206. }
  207. ############################### EDIT PROFILE FIELDS ###############################
  208. if (($_REQUEST['do'] == "edit") OR ($_REQUEST['do'] == "new2")) {
  209. // set form action for field editing
  210. if ($_REQUEST['do'] == "edit") {
  211. admin_header('User Fields');
  212. $user_field = $db->query_return("
  213. SELECT * FROM user_def
  214. WHERE id = '$id'
  215. ");
  216. echo "
  217. <form do="user_fields.php" method="post" name="fields">
  218. <input type="hidden" name="do" value="update">
  219. <input type="hidden" name="id" value="$user_field[id]">
  220. ";
  221. // set form action for new field creation
  222. } else {
  223. admin_header('User Fields', 'Add New Field');
  224. $user_field[formtype] = $type;
  225. echo "
  226. <form do="user_fields.php" method="post"  name="fields">
  227. <input type="hidden" name="do" value="new3">
  228. <input type="hidden" name="type" value="$user_field[formtype]">
  229. ";
  230. }
  231. ############################### LANGUAGE BITS ############################### 
  232. $user_field[display_name] = unserialize($user_field[display_name]);
  233. $user_field[description] = unserialize($user_field[description]);
  234. $user_field[error_message] = unserialize($user_field[error_message]);
  235. if ($settings[language_on]) {
  236. $name = "<div id="name"><table cellpadding="2" cellspacing="0">";
  237. $description = "<div id="description"><table cellpadding="2" cellspacing="0">";
  238. $error = "<div id="error"><table cellpadding="2" cellspacing="0">";
  239. $db->query("SELECT * FROM languages WHERE is_selectable = 1");
  240. while ($lang = $db->row_array()) {
  241. $name .= "<tr><td><b>$lang[name]</b>:</td><td>" . form_input($lang[id], $user_field[display_name][$lang[id]], 30, 'display_name') . "</td></tr>";
  242. $description .= "<tr><td><b>$lang[name]</b>:</td><td>" . form_textarea($lang[id], 40, 5, $user_field[description][$lang[id]], 'description') . "</td></tr>";
  243. $error .= "<tr><td><b>$lang[name]</b>:</td><td>" . form_textarea($lang[id], 40, 5, $user_field[error_message][$lang[id]], 'error_message') . "</td></tr>";
  244. }
  245. $name .= "</table><input type="button" value="Collapse Language Options" onclick="oc('name');oc('name2')"></div><div id="name2"><input type="button" value="Expand Language Options" onclick="oc('name');oc('name2');"><div><script>oc('name')</script>";
  246. $description .= "</table><input type="button" value="Collapse Language Options" onclick="oc('description');oc('description2')"></div><div id="description2"><input type="button" value="Expand Language Options" onclick="oc('description');oc('description2');"><div><script>oc('description')</script>";
  247. $error .= "</table><input type="button" value="Collapse Language Options" onclick="oc('error');oc('error2')"></div><div id="error2"><input type="button" value="Expand Language Options" onclick="oc('error');oc('error2');"><div><script>oc('error')</script>";
  248. } else {
  249. $name = form_input('display_name', $user_field[display_name][$settings[default_language]]);
  250. $description = form_textarea('description', 50, 5, $user_field[description][$settings[default_language]]);
  251. $error = form_textarea('error_message', 50, 5, $user_field[error_message][$settings[default_language]]);
  252. }
  253. ############################### STANDARD FOR ALL ############################### 
  254. // display options
  255. $table[] = array('<b>Display Name</b><br />This is the name of the field that will be presented to technicians and users', $name);
  256. // show different message if new/edit
  257. if ($_REQUEST['do'] == "edit") {
  258. $table[] = array('<b>Database Name</b><br />This is the name of the field as it is in the database. This is the name you would use to call the value in your templates', $user_field[name]);
  259. } else {
  260. $table[] = array('<b>Database Name</b><br />This is the name of the field as it is in the database. This is the name you would use to call the value in your templates', '<I>Generated upon field creation</I>');
  261. }
  262. $table[] = array('<b>Description</b><br />The description that will be presented for this field to your users', $description);
  263. if ($user_field[formtype] != "system") {
  264. $table[] = array('<b>Display During Registration</b><br />Do you wish this field to be presented to the user during registration?', form_radio_yn('user_start', '', $user_field[user_start]));
  265. }
  266. $width = array('60%', '40%');
  267. table_header('Field Details');
  268. table_content('', $table, '', '', '', '', $width);
  269. table_footer();
  270. unset($table, $width);
  271. // field permissions
  272. $table[] = array('<b>User Viewable</b><br />Do you wish to allow your users to view this field?', form_radio_yn('user_viewable', '', $user_field[user_viewable]));
  273. if ($user_field[formtype] != "system") {
  274. $table[] = array('<b>User Editable</b><br />Do you wish to allow your users to edit the data held in this field?', form_radio_yn('user_editable', '', $user_field[user_editable]));
  275. }
  276. $table[] = array('<b>Tech Viewable</b><br />Do you wish to allow your staff to view this field?', form_radio_yn('tech_viewable', '', $user_field[tech_viewable]));
  277. if ($user_field[formtype] != "system") {
  278. $table[] = array('<b>Tech Editable</b><br />Do you wish to allow your staff to edit this field?', form_radio_yn('tech_editable', '', $user_field[tech_editable]));
  279. }
  280. $width = array('60%', '40%');
  281. table_header('Field Permissions');
  282. table_content('', $table, '', '', '', '', $width);
  283. table_footer();
  284. unset($table, $width);
  285. ############################### INPUT ############################### 
  286. if ($user_field[formtype] == "input") {
  287. echo form_hidden('formtype', 'input');
  288. // regex
  289. $table[] = array('<b>Minimum Characters</b><br />You can set a minimum number of characters that the user must enter in this field. Set to 0 for no stipulation (and to allow the field to be left empty)', form_input('minlength', $user_field[minlength], '3'));
  290. $table[] = array('<b>Maximum Characters</b><br />You can set a maximum number of characters that the user may enter. Set to 0 to allow for unlimited entry', form_input('maxlength', $user_field[maxlength], '3'));
  291. $table[] = array('<b>Custom Regex</b><br />You may use a custom regex to validate the input. You can find details about creating these PHP Manual. A custom regex overrides any stipulations on minimum or maximum field length', form_input('regex', $user_field[regex], '45'));
  292. $table[] = array('<b>Error Message</b><br />If the user enters text that fails the criteria you have specified above, this is the error that will be presented', $error);
  293. $width = array('60%', '40%');
  294. table_header('Field Criteria');
  295. table_content('', $table, '', '', '', '', $width);
  296. table_footer();
  297. unset($table, $width);
  298. // default value
  299. $table[] = array('<b>Default Value</b><br />You may specify a default starting value here', form_input('default_value', $user_field[default_value], '45'));
  300. $table[] = array('<b>Parsed Default Value</b><br />You may specify a parsed default value. This overrides any default value you may have set.', form_input('parsed_default_value', $user_field[parsed_default_value], '45'));
  301. $width = array('60%', '40%');
  302. table_header('Default Value');
  303. table_content('', $table, '', '', '', '', $width);
  304. table_footer();
  305. unset($table, $width);
  306. // display properties
  307. $table[] = array('<b>Length</b><br />How long do you wish the INPUT field to be?', form_input('length', $user_field[length], '4'));
  308. $table[] = array('<b>Order</b><br />What order you wish the field to be displayed in relation to your other fields?', form_input('displayorder', $user_field[displayorder], '4'));
  309. $width = array('60%', '40%');
  310. table_header('Field Display Properties');
  311. table_content('', $table, '', '', '', '', $width);
  312. table_footer();
  313. unset($table, $width);
  314. ############################### TEXTAREA ############################### 
  315. } elseif ($user_field[formtype] == "textarea") {
  316. echo form_hidden('formtype', 'textarea');
  317. // regex
  318. $table[] = array('<b>Minimum Characters</b><br />You can set a minimum number of characters that the user must enter in this field. Set to 0 for no stipulation (and to allow the field to be left empty)', form_input('minlength', $user_field[minlength], '3'));
  319. $table[] = array('<b>Maximum Characters</b><br />You can set a maximum number of characters that the user may enter. Set to 0 to allow for unlimited entry', form_input('maxlength', $user_field[maxlength], '3'));
  320. $table[] = array('<b>Custom Regex</b><br />You may use a custom regex to validate the input. You can find details about creating these in PHP's manual. A custom regex overrides any stipulations on minimum or maximum field length', form_input('regex', $user_field[regex], '45'));
  321. $table[] = array('<b>Error Message</b><br />If the user enters text that fails the criteria you have specified above, this is the error that will be presented', $error);
  322. $width = array('60%', '40%');
  323. table_header('Field Criteria');
  324. table_content('', $table, '', '', '', '', $width);
  325. table_footer();
  326. unset($table, $width);
  327. // default value
  328. $table[] = array('<b>Default Value</b><br />You may specify a default starting value here', form_input('default_value', $user_field[default_value], '45'));
  329. $table[] = array('<b>Parsed Default Value</b><br />You may specify a parsed default value. This overrides any default value you may have set.', form_input('parsed_default_value', $user_field[parsed_default_value], '45'));
  330. $width = array('60%', '40%');
  331. table_header('Default Value');
  332. table_content('', $table, '', '', '', '', $width);
  333. table_footer();
  334. unset($table, $width);
  335. // display properties
  336. $table[] = array('<b>Length</b><br />How long do you wish the TEXTAREA field to be?', form_input('length', $user_field[length], '4'));
  337. $table[] = array('<b>Height</b><br />How many lines do you wish the TEXTAREA field to have?', form_input('height', $user_field[height], '4'));
  338. $table[] = array('<b>Order</b><br />What order you wish the field to be displayed in relation to your other fields?', form_input('displayorder', $user_field[displayorder], '4'));
  339. $width = array('60%', '40%');
  340. table_header('Field Display Properties');
  341. table_content('', $table, '', '', '', '', $width);
  342. table_footer();
  343. unset($table, $width);
  344. ############################### RADIO ############################### 
  345. } elseif ($user_field[formtype] == "radio") {
  346. echo form_hidden('formtype', 'radio');
  347. // regex
  348. $table[] = array('<b>Require a Selection</b><br />Set yes to require the selection of a radio element)', form_radio_yn('required', '', $user_field[required]));
  349. $table[] = array('<b>Error Message</b><br />The error message to be displayed if the user does not select an option. If you are enabling the extra INPUT field and have a custom regex which is not satisfied then this message would then be displayed.', $error);
  350. $width = array('60%', '40%');
  351. table_header('Field Criteria');
  352. table_content('', $table, '', '', '', '', $width);
  353. table_footer();
  354. unset($table, $width);
  355. // display properties
  356. $table[] = array('<b>Order</b><br />What order you wish the field to be displayed in relation to your other fields?', form_input('displayorder', $user_field[displayorder], '3'));
  357. $table[] = array('<b>Radio Elements Per line</b><br />How many radio elements do you want to display per line?', form_input('perline', $user_field[perline], '3'));
  358. $width = array('60%', '40%');
  359. table_header('Field Display Properties');
  360. table_content('', $table, '', '', '', '', $width);
  361. table_footer();
  362. unset($table, $width);
  363. // extra bit
  364. $table[] = array('<b>Allow Alternative Input</b><br />Selecting Yes will generate an alternative INPUT field that will allow your user to enter custom information if none of the SELECT options are suitable. If you enable this feature it will override the requirement of a selection you may have set earlier.', form_radio_yn('extrainput', '', $user_field[extrainput], '', 'onClick="extrainput2();"'));
  365. $table[] = array('<b>Minimum Characters</b><br />You can set a minimum number of characters that the user must enter in this field. Set to 0 for no stipulation (and to allow the field to be left empty)', form_input('minlength', $user_field[minlength], '3'));
  366. $table[] = array('<b>Maximum Characters</b><br />You can set a maximum number of characters that the user may enter. Set to 0 to allow for unlimited entry', form_input('maxlength', $user_field[maxlength], '3'));
  367. $table[] = array('<b>Custom Regex</b><br />You may use a custom regex to validate the input. You can find details about creating these in PHP's manual.', form_input('regex', $user_field[regex], '45'));
  368. $table[] = array('<b>Length</b><br />How long do you wish the INPUT field to be?', form_input('length', $user_field[length], '3'));
  369. $table[] = array('<b>Extrainput Text</b><br />The text to display to explain the presence of the input box. For example <I>Or enter your own option</I>', form_input('extrainput_text', $user_field[extrainput_text], 45));
  370. $table[] = array('<b>Extrainput Location</b><br />Do you want the INPUT field to be displayed on a new line?', form_radio_yn('extrainput_location', '', $user_field[extrainput_location]));
  371. $width = array('60%', '40%');
  372. table_header('Extra Input');
  373. table_content('', $table, '', '', '', '', $width);
  374. table_footer();
  375. unset($table, $width);
  376. $field_data = unserialize($user_field[data]);
  377. // get max number for creating new fields
  378. if (is_array($field_data)) {
  379. while (list ($key, $val) = each ($field_data)) {
  380. $array_count[] = $field_data[$key][0];
  381. }
  382. $max = max($array_count);
  383. reset($field_data);
  384. }
  385. $field_data[] = array($max+1, '', '', '', '');
  386. $field_data[] = array($max+2, '', '', '', '');
  387. $field_data[] = array($max+3, '', '', '', '');
  388. $field_data[] = array($max+4, '', '', '', '');
  389. $field_data[] = array($max+5, '', '', '', '');
  390. while (list ($key, $val) = each ($field_data)) {
  391. $table[] = array(
  392. $val[0] . form_hidden($key, '1', $arrayto='elementid'),
  393. form_input($val[0], $val[1], '3', 'order'), 
  394. iff($val[2], "<B>$val[2]</B>", "<I>n/a</I>"),
  395. form_input($val[0], $val[2], '45', 'name'), 
  396. form_radio_yn($val[0], 'start', $val[4])
  397. );
  398. }
  399. $table[] = array('<I>To delete a field, empty its New / Edit value. Note this will also delete any
  400. data associated with that field.</I>');
  401. $columns = array('ID', 'Order', 'Current Value', 'New / Edit Value', 'Select by Default');
  402. table_header('Field Data');
  403. table_content($columns, $table);
  404. table_footer();
  405. unset($table);
  406. // javascript to control options
  407. ?>
  408. <SCRIPT>
  409. function extrainput2() {
  410. var value;
  411. for (value = 0; value < document.fields.extrainput.length; value++)
  412. {
  413. if (document.fields.extrainput[value].checked == true)
  414. {
  415. yesno = document.fields.extrainput[value].value;
  416. }
  417. }
  418. if (yesno == '1')
  419. {
  420. document.fields.minlength.disabled=false;
  421. document.fields.maxlength.disabled=false;
  422. document.fields.regex.disabled=false;
  423. document.fields.length.disabled=false;
  424. document.fields.extrainput_location[0].disabled=false;
  425. document.fields.extrainput_location[1].disabled=false;
  426. document.fields.extrainput_text.disabled=false;
  427. } else {
  428. document.fields.minlength.disabled=true;
  429. document.fields.maxlength.disabled=true;
  430. document.fields.regex.disabled=true;
  431. document.fields.length.disabled=true;
  432. document.fields.extrainput_location[0].disabled=true;
  433. document.fields.extrainput_location[1].disabled=true;
  434. document.fields.extrainput_text.disabled=true;
  435. }
  436. }
  437. extrainput2();
  438. </SCRIPT>
  439. <?
  440. ############################### SELECT ############################### 
  441. } elseif ($user_field[formtype] == "select") {
  442. echo form_hidden('formtype', 'select');
  443. // regex
  444. $table[] = array('<b>Require a Selection</b><br />Do you wish to require a selection. Note this field has no affect if you allow multiple selections, you should use the minimum option setting to control the amount of required information.', form_radio_yn('required', '', $user_field[required]));
  445. $table[] = array('<b>Allow multiple selections</b><br />By allowing multiple selections your users can pick a number of options from the select menu. In terms of HTML, the element becomes a multiselect field. <b>Note:</b> enabling multiselect disables the alternative input option', form_radio_yn('multiselect', '', $user_field[multiselect], '', 'onClick="multipleselect();"'));
  446. $table[] = array('<b>Maximum Options</b><br />The maximum number of options that can be selected. Set a 0 to have no maximum. (only applies if you are allowing multiple selections)', form_input('maxoptions', $user_field[maxoptions], '3'));
  447. $table[] = array('<b>Minimum Options</b><br />The minimum amount of options that must be selected. Set a 0 to require no minumum. (only applies if you are allowing multiple selections otherwise use the require a selection setting)', form_input('minoptions', $user_field[minoptions], '3'));
  448. $table[] = array('<b>Error Message</b><br />The error message to be displayed if the user does not select an option. If you are enabling the extra INPUT field and have a custom regex which is not satisfied then this message would then be displayed.', $error);
  449. $width = array('60%', '40%');
  450. table_header('Field Criteria');
  451. table_content('', $table, '', '', '', '', $width);
  452. table_footer();
  453. unset($table, $width);
  454. // display properties
  455. $table[] = array('<b>Order</b><br />What order you wish the field to be displayed in relation to your other fields?', form_input('displayorder', $user_field[displayorder], '3'));
  456. $table[] = array('<b>Height</b><br />How many rows do you wish to display for the select menu', form_input('height', $user_field[height], '3'));
  457. $width = array('60%', '40%');
  458. table_header('Field Display Properties');
  459. table_content('', $table, '', '', '', '', $width);
  460. table_footer();
  461. unset($table, $width);
  462. // extra bit
  463. $table[] = array('<b>Allow Alternative Input</b><br />Selecting Yes will generate an alternative INPUT field that will allow your user to enter custom information if none of the SELECT options are suitable. If you enable this feature it will override the requirement of a selection you may have set earlier.', form_radio_yn('extrainput', '', $user_field[extrainput], '', 'onClick="extrainput2();"'));
  464. $table[] = array('<b>Minimum Characters</b><br />You can set a minimum number of characters that the user must enter in this field. Set to 0 for no stipulation (and to allow the field to be left empty)', form_input('minlength', $user_field[minlength], '3'));
  465. $table[] = array('<b>Maximum Characters</b><br />You can set a maximum number of characters that the user may enter. Set to 0 to allow for unlimited entry', form_input('maxlength', $user_field[maxlength], '3'));
  466. $table[] = array('<b>Custom Regex</b><br />You may use a custom regex to validate the input. You can find details about creating these in PHP's manual.', form_input('regex', $user_field[regex], '45'));
  467. $table[] = array('<b>Length</b><br />How long do you wish the INPUT field to be?', form_input('length', $user_field[length], '3'));
  468. $table[] = array('<b>Extrainput Text</b><br />The text to display to explain the presence of the input box. For example <I>Or enter your own option</I>', form_input('extrainput_text', $user_field[extrainput_text], 45));
  469. $table[] = array('<b>Extrainput Location</b><br />Do you want the INPUT field to be displayed on a new line?', form_radio_yn('extrainput_location', '', $user_field[extrainput_location]));
  470. $width = array('60%', '40%');
  471. table_header('Extra Input');
  472. table_content('', $table, '', '', '', '', $width);
  473. table_footer();
  474. unset($table, $width);
  475. $field_data = unserialize($user_field[data]);
  476. // get max number for creating new fields
  477. if (is_array($field_data)) {
  478. while (list ($key, $val) = each ($field_data)) {
  479. $array_count[] = $field_data[$key][0];
  480. }
  481. $max = max($array_count);
  482. reset($field_data);
  483. }
  484. $field_data[] = array($max+1, '', '', '');
  485. $field_data[] = array($max+2, '', '', '');
  486. $field_data[] = array($max+3, '', '', '');
  487. $field_data[] = array($max+4, '', '', '');
  488. $field_data[] = array($max+5, '', '', '');
  489. while (list ($key, $val) = each ($field_data)) {
  490. $table[] = array(
  491. $val[0] . form_hidden($val[0], '1', $arrayto='elementid'),
  492. form_input($val[0], $val[1], '3', 'order'), 
  493. iff($val[2], "<B>$val[2]</B>", "<I>n/a</I>"),
  494. form_input($val[0], $val[2], '45', 'name'),
  495. form_radio_yn($val[0], 'start', $val[3])
  496. );
  497. }
  498. $table[] = array('<I>To delete a field, empty its New / Edit value. Note this will also delete any
  499. data associated with that field.</I>');
  500. $columns = array('ID', 'Order', 'Current Value', 'New / Edit Value', 'Select by Default');
  501. table_header('Field Data');
  502. table_content($columns, $table);
  503. table_footer();
  504. unset($table);
  505. // javascript to control options
  506. ?>
  507. <SCRIPT>
  508. function extrainput2() {
  509. var value;
  510. for (value = 0; value < document.fields.extrainput.length; value++)
  511. {
  512. if (document.fields.extrainput[value].checked == true)
  513. {
  514. yesno = document.fields.extrainput[value].value;
  515. }
  516. }
  517. if (yesno == '1')
  518. {
  519. document.fields.minlength.disabled=false;
  520. document.fields.maxlength.disabled=false;
  521. document.fields.regex.disabled=false;
  522. document.fields.length.disabled=false;
  523. document.fields.extrainput_location[0].disabled=false;
  524. document.fields.extrainput_location[1].disabled=false;
  525. document.fields.extrainput_text.disabled=false;
  526. } else {
  527. document.fields.minlength.disabled=true;
  528. document.fields.maxlength.disabled=true;
  529. document.fields.regex.disabled=true;
  530. document.fields.length.disabled=true;
  531. document.fields.extrainput_location[0].disabled=true;
  532. document.fields.extrainput_location[1].disabled=true;
  533. document.fields.extrainput_text.disabled=true;
  534. }
  535. }
  536. function multipleselect() {
  537. var value;
  538. for (value = 0; value < document.fields.multiselect.length; value++)
  539. {
  540. if (document.fields.multiselect[value].checked == true)
  541. {
  542. yesno = document.fields.multiselect[value].value;
  543. }
  544. }
  545. if (yesno == '1') {
  546. document.fields.maxoptions.disabled=false;
  547. document.fields.minoptions.disabled=false;
  548. document.fields.required[0].disabled=true;
  549. document.fields.required[1].disabled=true;
  550. document.fields.extrainput[1].checked=true;
  551. extrainput2();
  552. document.fields.extrainput[0].disabled=true;
  553. } else {
  554. document.fields.maxoptions.disabled=true;
  555. document.fields.minoptions.disabled=true;
  556. document.fields.required[0].disabled=false;
  557. document.fields.required[1].disabled=false;
  558. document.fields.extrainput[0].disabled=false;
  559. }
  560. }
  561. extrainput2();
  562. multipleselect();
  563. </SCRIPT>
  564. <?
  565. ############################### CHECKBOX ############################### 
  566. } elseif ($user_field[formtype] == "checkbox") {
  567. echo form_hidden('formtype', 'checkbox');
  568. // regex
  569. $table[] = array('<b>Maximum Options</b><br />The maximum amount of options that can be selected. (Set a 0 to have no maximum.)', form_input('maxoptions', $user_field[maxoptions], '3'));
  570. $table[] = array('<b>Minimum Options</b><br />The minimum amount of options that must be selected. (Set as 0 to require no minimum number of options.)', form_input('minoptions', $user_field[minoptions], '3'));
  571. $table[] = array('<b>Error Message</b><br />The error message to be displayed if the user does not select an option. If you are enabling the extra INPUT field and have a custom regex which is not satisfied then this message would then be displayed.', $error);
  572. $width = array('60%', '40%');
  573. table_header('Field Criteria');
  574. table_content('', $table, '', '', '', '', $width);
  575. table_footer();
  576. unset($table, $width);
  577. // display properties
  578. $table[] = array('<b>Order</b><br />What order you wish the field to be displayed in relation to your other fields?', form_input('displayorder', $user_field[displayorder], '3'));
  579. $table[] = array('<b>Checkboxes Per line</b><br />How many checkboxes do you want to display per line?', form_input('perline', $user_field[perline], '3'));
  580. $width = array('60%', '40%');
  581. table_header('Field Display Properties');
  582. table_content('', $table, '', '', '', '', $width);
  583. table_footer();
  584. unset($table, $width);
  585. $field_data = unserialize($user_field[data]);
  586. // get max number for creating new fields
  587. if (is_array($field_data)) {
  588. while (list ($key, $val) = each ($field_data)) {
  589. $array_count[] = $field_data[$key][0];
  590. }
  591. $max = max($array_count);
  592. reset($field_data);
  593. }
  594. $field_data[] = array($max+1, '', '', '', '');
  595. $field_data[] = array($max+2, '', '', '', '');
  596. $field_data[] = array($max+3, '', '', '', '');
  597. $field_data[] = array($max+4, '', '', '', '');
  598. $field_data[] = array($max+5, '', '', '', '');
  599. while (list ($key, $val) = each ($field_data)) {
  600. $table[] = array(
  601. $val[0] . form_hidden($key, '1', $arrayto='elementid'),
  602. form_input($val[0], $val[1], '3', 'order'), 
  603. iff($val[2], "<B>$val[2]</B>", "<I>n/a</I>"),
  604. form_input($val[0], $val[2], '45', 'name'),
  605. form_radio_yn($val[0], 'start', $val[4])
  606. );
  607. }
  608. $table[] = array('<I>To delete a field, empty its New / Edit value. Note this will also delete any
  609. data associated with that field.</I>');
  610. $columns = array('ID', 'Order', 'Current Value', 'New / Edit Value', 'Select by Default');
  611. table_header('Field Data');
  612. table_content($columns, $table);
  613. table_footer();
  614. unset($table);
  615. }
  616. ############################### FINISH OFF ###############################
  617. // show different form button if new/edit
  618. if ($_REQUEST['do'] == "edit") {
  619. echo "<br /><center><input type="submit" name="submit" value="Update Field Options"></center></form>";
  620. } else {
  621. echo "<br /><center><input type="submit" name="submit" value="Create New Field"></center></form>";
  622. }
  623. }
  624. ############################### SELECT TYPE OF NEW FIELD TO CREATE ###############################
  625. if ($_REQUEST['do'] == "add") {
  626. admin_header('User Fields', 'Add New Field');
  627. $table[] = array('<b>INPUT</b>', 'This field allows the user to enter text on one line. Useful for words and short sentences', '<a href="user_fields.php?do=new2&type=input">create</a>');
  628. $table[] = array('<b>TEXTAREA</b>', 'Allows for text input across a number of lines. Useful for where more information is required.', '<a href="user_fields.php?do=new2&type=textarea">create</a>');
  629. $table[] = array('<b>SELECT</b>', 'This field allows the user to select from a number of options contained in a list', '<a href="user_fields.php?do=new2&type=select">create</a>');
  630. $table[] = array('<b>RADIO</b>', 'Allows the user from pick one from a number of options where the options are displayed as radio buttons', '<a href="user_fields.php?do=new2&type=radio">create</a>');
  631. $table[] = array('<b>CHECKBOX</b>', 'Allows the user to select a number of options where the options are displayed as checkboxes', '<a href="user_fields.php?do=new2&type=checkbox">create</a>');
  632. table_header('Create New Field');
  633. table_content('', $table);
  634. table_footer();
  635. unset($table, $width);
  636. }
  637. ############################### DELETE CUSTOM PROFILE FIELDS ###############################
  638. if ($_REQUEST['do'] == "delete") {
  639. $field = $db->query_return("SELECT name FROM user_def WHERE id = " . intval($id));
  640. // delete the field and column
  641. $db->query("DELETE FROM user_def WHERE id = " . intval($id));
  642. $db->query("ALTER TABLE user DROP $field[name]");
  643. jump('user_fields.php?action=view', 'Custom Profile Field Deleted');
  644. }
  645. ############################### LIST CUSTOM PROFILE FIELDS ###############################
  646. if ($_REQUEST['do'] == "view") {
  647. admin_header('User Fields', 'View Fields');
  648. // Fetch indexes
  649. $db->query("SHOW INDEX FROM user");
  650. while ($index = $db->row_array()) {
  651. $indexed[$index['Column_name']] = 1;
  652. }
  653. // Fetch custom fields
  654. $db->query("
  655. SELECT * FROM user_def
  656. ORDER BY displayorder
  657. ");
  658. while ($user_fields = $db->row_array()) {
  659. $user_fields['display_name'] = unserialize($user_fields['display_name']);
  660. $user_fields['display_name'] = $user_fields['display_name'][$settings['default_language']];
  661. if ($indexed[$user_fields['name']]) {
  662. $index = jprompt('This will remove the index for this field. Searches on this field may take longer, but changes to the users table that involve this field may be faster after this change. This operation may take some time if there are many users.', 
  663. "user_fields.php?do=dropindex&id=$user_fields[id]",
  664. 'Remove Index');
  665. } else {
  666. $index = jprompt('This will create an index for this field. Searches on this field may be faster, but changes to the users table that involve this field may take longer after this change. This operation may take some time if there are many users.', 
  667. "user_fields.php?do=createindex&id=$user_fields[id]",
  668. 'Create Index');
  669. }
  670. ${"table_$user_fields[formtype]"}[] = array(
  671. $user_fields['display_name'], 
  672. $user_fields['name'].'</center>', 
  673. ifynb($user_fields['user_viewable']),
  674. ifynb($user_fields['user_editable']),
  675. ifynb($user_fields['tech_viewable']),
  676. ifynb($user_fields['tech_editable']),
  677. $index,
  678. $user_fields['displayorder'],
  679. "<a href="user_fields.php?do=edit&id=$user_fields[id]">Edit</a>",
  680. jprompt('Are you sure you want to delete this custom field?', "user_fields.php?do=delete&id=$user_fields[id]", 'Delete')
  681. );
  682. }
  683. // build the row headings
  684. $columns = array('Display name', 'SQL name', 'User Viewable', 'User Editable', 'Tech Viewable', 'Tech Editable', 'Index', 'Order', 'Edit', 'Delete');
  685. table_header('Input Fields');
  686. table_content($columns, $table_input);
  687. table_footer();
  688. table_header('Select Fields');
  689. table_content($columns, $table_select);
  690. table_footer();
  691. table_header('Textarea Fields');
  692. table_content($columns, $table_textarea);
  693. table_footer();
  694. table_header('Radio Fields');
  695. table_content($columns, $table_radio);
  696. table_footer();
  697. table_header('Checkbox Fields');
  698. table_content($columns, $table_checkbox);
  699. table_footer();
  700. $columns = array('Display name', 'SQL name', 'User Viewable', 'Tech Viewable', 'Indexed', 'Order', 'Edit', 'Delete');
  701. }
  702. ##############################################################
  703. admin_footer();
  704. php?>