Advertisement
Guest User

Users extended

a guest
Aug 16th, 2010
903
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.22 KB | None | 0 0
  1. <?php
  2. /*
  3. * e107 website system
  4. *
  5. * Copyright (C) 2008-2010 e107 Inc (e107.org)
  6. * Released under the terms and conditions of the
  7. * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
  8. *
  9. * Extended user field management
  10. *
  11. * $URL: https://e107.svn.sourceforge.net/svnroot/e107/trunk/e107_0.7/e107_admin/users_extended.php $
  12. * $Id: users_extended.php 11551 2010-05-24 19:58:43Z mcfly_e107 $
  13. *
  14. */
  15. require_once("../class2.php");
  16. if(varset($_POST['eu_action']) && !varset($_POST['__referer']))
  17. {
  18. header('location:'.e_BASE.'index.php');
  19. exit;
  20. }
  21. if (!getperms("4")) {
  22. header("location:".e_BASE."index.php");
  23. exit;
  24. }
  25. if (isset($_POST['cancel']))
  26. {
  27. header("location:".e_SELF);
  28. exit;
  29. }
  30. if (isset($_POST['cancel_cat']))
  31. {
  32. header("location:".e_SELF."?cat");
  33. exit;
  34. }
  35.  
  36. $e_sub_cat = 'user_extended';
  37. $user = new users_ext;
  38. $curtype = '1';
  39. require_once(e_HANDLER."calendar/calendar_class.php");
  40. $cal = new DHTML_Calendar(true);
  41. require_once("auth.php");
  42. require_once(e_HANDLER."user_extended_class.php");
  43. require_once(e_HANDLER."userclass_class.php");
  44.  
  45.  
  46. $ue = new e107_user_extended;
  47. $message = '';
  48.  
  49. if (e_QUERY)
  50. {
  51. $tmp = explode(".", e_QUERY);
  52. $action = $tmp[0];
  53. $sub_action = varset($tmp[1],'');
  54. $id = varset($tmp[2],0);
  55. unset($tmp);
  56. }
  57.  
  58.  
  59.  
  60. if (isset($_POST['up_x']))
  61. {
  62. $qs = explode(".", $_POST['id']);
  63. $_id = $qs[0];
  64. $_order = $qs[1];
  65. $_parent = $qs[2];
  66. $sql->db_Update("user_extended_struct", "user_extended_struct_order=user_extended_struct_order+1 WHERE user_extended_struct_type > 0 AND user_extended_struct_parent = {$_parent} AND user_extended_struct_order ='".($_order-1)."'");
  67. $sql->db_Update("user_extended_struct", "user_extended_struct_order=user_extended_struct_order-1 WHERE user_extended_struct_type > 0 AND user_extended_struct_parent = {$_parent} AND user_extended_struct_id='".$_id."'");
  68. }
  69.  
  70.  
  71. if (isset($_POST['down_x']))
  72. {
  73. $qs = explode(".", $_POST['id']);
  74. $_id = $qs[0];
  75. $_order = $qs[1];
  76. $_parent = $qs[2];
  77. $sql->db_Update("user_extended_struct", "user_extended_struct_order=user_extended_struct_order-1 WHERE user_extended_struct_type > 0 AND user_extended_struct_parent = {$_parent} AND user_extended_struct_order='".($_order+1)."'");
  78. $sql->db_Update("user_extended_struct", "user_extended_struct_order=user_extended_struct_order+1 WHERE user_extended_struct_type > 0 AND user_extended_struct_parent = {$_parent} AND user_extended_struct_id='".$_id."'");
  79. }
  80.  
  81.  
  82. if (isset($_POST['catup_x']))
  83. {
  84. $qs = explode(".", $_POST['id']);
  85. $_id = $qs[0];
  86. $_order = $qs[1];
  87. $sql->db_Update("user_extended_struct", "user_extended_struct_order=user_extended_struct_order+1 WHERE user_extended_struct_type = 0 AND user_extended_struct_order='".($_order-1)."'");
  88. $sql->db_Update("user_extended_struct", "user_extended_struct_order=user_extended_struct_order-1 WHERE user_extended_struct_type = 0 AND user_extended_struct_id='".$_id."'");
  89. }
  90.  
  91.  
  92. if (isset($_POST['catdown_x']))
  93. {
  94. $qs = explode(".", $_POST['id']);
  95. $_id = $qs[0];
  96. $_order = $qs[1];
  97. $sql->db_Update("user_extended_struct", "user_extended_struct_order=user_extended_struct_order-1 WHERE user_extended_struct_type = 0 AND user_extended_struct_order='".($_order+1)."'");
  98. $sql->db_Update("user_extended_struct", "user_extended_struct_order=user_extended_struct_order+1 WHERE user_extended_struct_type = 0 AND user_extended_struct_id='".$_id."'");
  99. }
  100.  
  101.  
  102. if (isset($_POST['add_field']))
  103. {
  104. $ue_field_name = str_replace(' ','_',trim($_POST['user_field'])); // Replace space with underscore - better security
  105. if (preg_match('#^\w+$#',$ue_field_name) === 1) // Check for allowed characters, finite field length
  106. {
  107. if($_POST['user_type']==4)
  108. {
  109. $_POST['user_values'] = array($_POST['table_db'],$_POST['field_id'],$_POST['field_value'],$_POST['field_order']);
  110. }
  111. $new_values = make_delimited($_POST['user_values']);
  112. $new_parms = $tp->toDB($_POST['user_include']."^,^".$_POST['user_regex']."^,^".$_POST['user_regexfail']."^,^".$_POST['user_hide']);
  113.  
  114. // Check to see if its a reserved field name before adding to database
  115. if($ue->user_extended_reserved($ue_field_name))
  116. { // Reserved field name
  117. $message = "[user_".$tp->toHTML($ue_field_name)."] ".EXTLAN_74;
  118. }
  119. else
  120. {
  121. $result = admin_update($ue->user_extended_add($ue_field_name, $_POST['user_text'], $_POST['user_type'], $new_parms, $new_values, $_POST['user_default'], $_POST['user_required'], $_POST['user_read'], $_POST['user_write'], $_POST['user_applicable'], 0, $_POST['user_parent']), 'insert', EXTLAN_29);
  122. if(!$result)
  123. {
  124. $message = EXTLAN_75;
  125. }
  126. }
  127. }
  128. else
  129. {
  130. $message = EXTLAN_76." : ".$tp->toHTML($ue_field_name);
  131. }
  132. }
  133.  
  134.  
  135. if (isset($_POST['update_field']))
  136. {
  137. if($_POST['user_type']==4){
  138. $_POST['user_values'] = array($_POST['table_db'],$_POST['field_id'],$_POST['field_value'],$_POST['field_order']);
  139. }
  140. $upd_values = make_delimited($_POST['user_values']);
  141. $upd_parms = $tp->toDB($_POST['user_include']."^,^".$_POST['user_regex']."^,^".$_POST['user_regexfail']."^,^".$_POST['user_hide']);
  142. admin_update($ue->user_extended_modify($sub_action, $_POST['user_field'], $_POST['user_text'], $_POST['user_type'], $upd_parms, $upd_values, $_POST['user_default'], $_POST['user_required'], $_POST['user_read'], $_POST['user_write'], $_POST['user_applicable'], $_POST['user_parent']), 'update', EXTLAN_29);
  143. }
  144.  
  145.  
  146. if (isset($_POST['update_category']))
  147. {
  148. $name = trim($tp->toHTML($_POST['user_field']));
  149. admin_update($sql->db_Update("user_extended_struct","user_extended_struct_name = '{$name}', user_extended_struct_read = '{$_POST['user_read']}', user_extended_struct_write = '{$_POST['user_write']}', user_extended_struct_applicable = '{$_POST['user_applicable']}' WHERE user_extended_struct_id = '{$sub_action}'"), 'update', EXTLAN_43);
  150. }
  151.  
  152.  
  153. if (isset($_POST['add_category']))
  154. {
  155. $name = $tp->toHTML($_POST['user_field']);
  156. admin_update($sql->db_Insert("user_extended_struct","'0', '$name', '', 0, '', '', '', '{$_POST['user_read']}', '{$_POST['user_write']}', '0', '0', '{$_POST['user_applicable']}', '0', '0'"), 'insert', EXTLAN_40);
  157. }
  158.  
  159.  
  160. if (varset($_POST['eu_action'],'') == "delext")
  161. {
  162. list($_id, $_name) = explode(",",$_POST['key']);
  163. if($ue->user_extended_remove($_id, $_name))
  164. {
  165. $message = EXTLAN_30;
  166. }
  167. }
  168.  
  169. // Delete category
  170. if (varset($_POST['eu_action'],'') == "delcat")
  171. {
  172. list($_id, $_name) = explode(",",$_POST['key']);
  173. if (count($ue->user_extended_get_fields($_id)) > 0)
  174. {
  175. $message = EXTLAN_77;
  176. }
  177. elseif($ue->user_extended_remove($_id, $_name))
  178. {
  179. $message = EXTLAN_41;
  180. }
  181. }
  182.  
  183. if(isset($_POST['activate']))
  184. {
  185. $message .= field_activate();
  186. }
  187.  
  188. if(isset($_POST['deactivate']))
  189. {
  190. $message .= field_deactivate();
  191. }
  192.  
  193. if($sql->db_Select("user_extended_struct","DISTINCT(user_extended_struct_parent)"))
  194. {
  195. $plist = $sql->db_getList();
  196. foreach($plist as $_p)
  197. {
  198. $o = 0;
  199. if($sql->db_Select("user_extended_struct", "user_extended_struct_id", "user_extended_struct_parent = {$_p['user_extended_struct_parent']} && user_extended_struct_type != 0 ORDER BY user_extended_struct_order ASC"))
  200. {
  201. $_list = $sql->db_getList();
  202. foreach($_list as $r)
  203. {
  204. $sql->db_Update("user_extended_struct", "user_extended_struct_order = '{$o}' WHERE user_extended_struct_id = {$r['user_extended_struct_id']}");
  205. $o++;
  206. }
  207. }
  208. }
  209. }
  210.  
  211. if($message)
  212. {
  213. $ns->tablerender("", "<div style='text-align:center'><b>".$message."</b></div>");
  214. }
  215.  
  216. if(isset($_POST['table_db']) && !$_POST['add_field'] && !$_POST['update_field']){
  217. $action = "continue";
  218. $current['user_extended_struct_name'] = $_POST['user_field'];
  219. $current['user_extended_struct_parms'] = $_POST['user_include']."^,^".$_POST['user_regex']."^,^".$_POST['user_regexfail']."^,^".$_POST['user_hide'];
  220. $current['user_extended_struct_text'] = $_POST['user_text'];
  221. $current['user_extended_struct_type'] = $_POST['user_type'];
  222. $user->show_extended($current);
  223. }
  224.  
  225. if (!e_QUERY || $action == 'main')
  226. {
  227. $user->show_extended();
  228. }
  229.  
  230. if ($action == "editext")
  231. {
  232. if($sql->db_Select('user_extended_struct','*',"user_extended_struct_id = '{$sub_action}'"))
  233. {
  234. $tmp = $sql->db_Fetch();
  235. $user->show_extended($tmp);
  236. }
  237. else
  238. {
  239. $user->show_extended('new');
  240. }
  241. }
  242.  
  243. if($action == 'pre')
  244. {
  245. show_predefined();
  246. }
  247.  
  248. if($action == 'cat')
  249. {
  250. if(is_numeric($sub_action))
  251. {
  252. if($sql->db_Select('user_extended_struct','*',"user_extended_struct_id = '{$sub_action}'"))
  253. {
  254. $tmp = $sql->db_Fetch();
  255. }
  256. }
  257. $user->show_categories($tmp);
  258. }
  259.  
  260. require_once("footer.php");
  261.  
  262. class users_ext
  263. {
  264.  
  265. function show_extended($current = '')
  266. {
  267. global $sql, $ns, $ue, $curtype, $tp, $mySQLdefaultdb, $action, $sub_action;
  268.  
  269. $catList = $ue->user_extended_get_categories();
  270. $catList[0][0] = array('user_extended_struct_name' => EXTLAN_36);
  271. $catNums = array_keys($catList);
  272. $extendedList = $ue->user_extended_get_fields();
  273. $text = '';
  274.  
  275. if(!$current)
  276. { // Show existing fields
  277. $mode = 'show';
  278. $text = "<div style='text-align:center'>";
  279. $text .= "<table style='".ADMIN_WIDTH."' class='fborder'>
  280. <tr>
  281. <td class='fcaption'>".EXTLAN_1."</td>
  282. <td class='fcaption'>".EXTLAN_2."</td>";
  283. $text .="<td class='fcaption'>".EXTLAN_4."</td>
  284. <td class='fcaption'>".EXTLAN_5."</td>
  285. <td class='fcaption'>".EXTLAN_6."</td>
  286. <td class='fcaption'>".EXTLAN_7."</td>
  287. <td class='fcaption'>&nbsp;</td>
  288. <td class='fcaption'>".EXTLAN_8."</td>
  289. </tr>
  290. ";
  291.  
  292. foreach($catNums as $cn)
  293. {
  294. $text .= "
  295. <tr>
  296. <td class='forumheader' colspan='9' style='text-align:center'>{$catList[$cn][0]['user_extended_struct_name']}</td>
  297. </tr>
  298. ";
  299.  
  300. $i=0;
  301. if(count($extendedList))
  302. { // Show current extended fields
  303. foreach($extendedList[$cn] as $ext)
  304. {
  305. $fname = "user_".$ext['user_extended_struct_name'];
  306. $uVal = str_replace(chr(1), "", $ext['user_extended_struct_default']); // Is this right?
  307. $text .= "
  308. <tr>
  309. <td class='forumheader3'>{$ext['user_extended_struct_name']}<br />[".$tp->toHTML($ext['user_extended_struct_text'], FALSE, "defs")."]</td>
  310. <td class='forumheader3'>".$ue->user_extended_edit($ext,$uVal)."</td>
  311. <td class='forumheader3'>".($ext['user_extended_struct_required'] == 1 ? LAN_YES : LAN_NO)."</td>
  312. <td class='forumheader3'>".r_userclass_name($ext['user_extended_struct_applicable'])."</td>
  313. <td class='forumheader3'>".r_userclass_name($ext['user_extended_struct_read'])."</td>
  314. <td class='forumheader3'>".r_userclass_name($ext['user_extended_struct_write'])."</td>
  315. <td class='forumheader3' style='width:5px'>
  316. <form method='post' action='".e_SELF."'>
  317. <input type='hidden' name='id' value='{$ext['user_extended_struct_id']}.{$ext['user_extended_struct_order']}.{$ext['user_extended_struct_parent']}' />
  318. ";
  319. if($i > 0)
  320. {
  321. $text .= "
  322. <input type='image' alt='' title='".EXTLAN_26."' src='".e_IMAGE."/admin_images/up.png' name='up' value='{$ext['user_extended_struct_id']}.{$ext['user_extended_struct_order']}.{$ext['user_extended_struct_parent']}' />
  323. ";
  324. }
  325. if($i <= count($extendedList[$cn])-2)
  326. {
  327. $text .= "<input type='image' alt='' title='".EXTLAN_25."' src='".e_IMAGE."/admin_images/down.png' name='down' value='{$ext['user_extended_struct_id']}.{$ext['user_extended_struct_order']}.{$ext['user_extended_struct_parent']}' />";
  328. }
  329. $text .= "
  330. </form>
  331. </td>
  332. <td class='forumheader3' style='width:50px;text-align:center;'>
  333. <form method='post' action='".e_SELF."?extended' onsubmit='return confirm(\"".EXTLAN_27."\")'>
  334. <a style='text-decoration:none' href='".e_SELF."?editext.{$ext['user_extended_struct_id']}'>".ADMIN_EDIT_ICON."</a>
  335. <input type='hidden' name='__referer' value='".POST_REFERER."' />
  336. <input type='hidden' name='eu_action' value='delext' />
  337. <input type='hidden' name='key' value='{$ext['user_extended_struct_id']},{$ext['user_extended_struct_name']}' />
  338. <input type='image' title='".LAN_DELETE."' name='eudel' src='".ADMIN_DELETE_ICON_PATH."' />
  339. </form>
  340. </td>
  341. </tr>
  342. ";
  343. $i++;
  344. }
  345. }
  346. else
  347. {
  348. $text .= "
  349. <tr>
  350. <td colspan='8' class='forumheader3' style='text-align:center'>".EXTLAN_28."</td>
  351. </tr>
  352. ";
  353. }
  354. }
  355. //Show add/edit form
  356. $text .= "
  357. </table>";
  358. }
  359. else
  360. {
  361. if($current == 'new')
  362. {
  363. $mode = 'new';
  364. $current = array();
  365. $current_include = '';
  366. $current_regex = '';
  367. $current_regexfail = '';
  368. $current_hide = '';
  369. }
  370. else
  371. { // Editing existing definition
  372. $mode = 'edit';
  373. list($current_include, $current_regex, $current_regexfail, $current_hide) = explode("^,^",$current['user_extended_struct_parms']);
  374. }
  375.  
  376. $text .= "
  377. <form method='post' action='".e_SELF."?".e_QUERY."'>
  378. ";
  379. $text .= "<table style='".ADMIN_WIDTH."' class='fborder'> ";
  380. $text .= "
  381. <tr>
  382. <td style='width:30%;vertical-align:top' class='forumheader3'>".EXTLAN_10.":</td>
  383. <td style='width:70%' class='forumheader3' colspan='3'>user_";
  384. if(is_array($current) && $current['user_extended_struct_name'])
  385. {
  386. $text .= $current['user_extended_struct_name']."
  387. <input type='hidden' name='user_field' value='".$current['user_extended_struct_name']."' />
  388. ";
  389. }
  390. else
  391. {
  392. $text .= "
  393. <input class='tbox' type='text' name='user_field' size='40' value='".$current['user_extended_struct_name']."' maxlength='50' />
  394. ";
  395. }
  396. $text .= "
  397. <br /><span class='smalltext'>".EXTLAN_11."</span>
  398. </td>
  399. </tr>
  400.  
  401. <tr>
  402. <td style='width:30%;vertical-align:top' class='forumheader3'>".EXTLAN_12.":</td>
  403. <td style='width:70%' class='forumheader3' colspan='3'>
  404. <input class='tbox' type='text' name='user_text' size='40' value='".$current['user_extended_struct_text']."' maxlength='50' /><br />
  405. <span class='smalltext'>".EXTLAN_13."</span>
  406. </td>
  407. </tr>
  408. ";
  409.  
  410. $text .= "<tr>
  411. <td style='width:30%;vertical-align:top' class='forumheader3'>".EXTLAN_14."</td>
  412. <td style='width:70%' class='forumheader3' colspan='3'>
  413. <select onchange='changeHelp(this.value)' class='tbox' name='user_type' id='user_type'>";
  414. foreach($ue->user_extended_types as $key => $val)
  415. {
  416. $selected = ($current['user_extended_struct_type'] == $key) ? " selected='selected'": "";
  417. $text .= "<option value='".$key."' $selected>".$val."</option>";
  418. }
  419. $curtype = $current['user_extended_struct_type'];
  420. if(!$curtype)
  421. {
  422. $curtype = '1';
  423. }
  424. $text .= "
  425. </select>
  426. </td></tr>";
  427.  
  428.  
  429.  
  430. $text .= "
  431. <tr>
  432. <td style='width:30%;vertical-align:top' class='forumheader3'>".EXTLAN_3."</td>
  433. <td style='width:70%' class='forumheader3' colspan='3'>";
  434. // Start of Values ---------------------------------
  435.  
  436. $val_hide = ($current['user_extended_struct_type'] != 4) ? "visible" : "none";
  437.  
  438. $text .= "<div id='values' style='display:$val_hide'>\n";
  439. $text .= "<div id='value_container' >\n";
  440. $curVals = explode(",",$current['user_extended_struct_values']);
  441. if(count($curVals) == 0){
  442. $curVals[]='';
  443. }
  444. $i=0;
  445. foreach($curVals as $v){
  446. $id = $i ? "" : " id='value_line'";
  447. $i++;
  448. $text .= "
  449. <span {$id}>
  450. <input class='tbox' type='text' name='user_values[]' size='40' value='{$v}' /></span><br />";
  451. }
  452. $text .= "
  453. </div>
  454. <input type='button' class='button' value='".EXTLAN_48."' onclick=\"duplicateHTML('value_line','value_container');\" />
  455. <br /><span class='smalltext'>".EXTLAN_17."</span></div>";
  456. // End of Values. --------------------------------------
  457. $db_hide = ($current['user_extended_struct_type'] == 4) ? "visible" : "none";
  458.  
  459. $text .= "<div id='db_mode' style='display:$db_hide'>\n";
  460. $text .= "<table style='width:70%;margin-left:0px'><tr><td>";
  461. $text .= EXTLAN_62."</td><td style='70%'><select style='width:99%' class='tbox' name='table_db' onchange=\"this.form.submit()\" >
  462. <option value='' class='caption'>".EXTLAN_61."</option>\n";
  463. $result = mysql_list_tables($mySQLdefaultdb);
  464. while ($row2 = mysql_fetch_row($result))
  465. {
  466. $fld = str_replace(MPREFIX,"",$row2[0]);
  467. $selected = (varset($_POST['table_db'],'') == $fld || $curVals[0] == $fld) ? " selected='selected'" : "";
  468. if (MPREFIX!='' && strpos($row2[0], MPREFIX)!==FALSE)
  469. {
  470. $text .= "<option value=\"".$fld."\" $selected>".$fld."</option>\n";
  471. }
  472. }
  473. $text .= " </select></td></tr>";
  474. if($_POST['table_db'] || $curVals[0]){
  475. // Field ID
  476. $text .= "<tr><td>".EXTLAN_63."</td><td><select style='width:99%' class='tbox' name='field_id' >\n
  477. <option value='' class='caption'>".EXTLAN_61."</option>\n";
  478. $table_list = ($_POST['table_db']) ? $_POST['table_db'] : $curVals[0] ;
  479. if($sql -> db_Select_gen("DESCRIBE ".MPREFIX."{$table_list}")){
  480. while($row3 = $sql -> db_Fetch()){
  481. $field_name=$row3[0];
  482. $selected = ($curVals[1] == $field_name) ? " selected='selected' " : "";
  483. $text .="<option value=\"$field_name\" $selected>".$field_name."</option>\n";
  484. }
  485. }
  486. $text .= " </select></td></tr><tr><td>";
  487. // Field Value
  488. $text .= EXTLAN_64."</td><td><select style='width:99%' class='tbox' name='field_value' >
  489. <option value='' class='caption'>".EXTLAN_61."</option>\n";
  490. $table_list = ($_POST['table_db']) ? $_POST['table_db'] : $curVals[0] ;
  491. if($sql -> db_Select_gen("DESCRIBE ".MPREFIX."{$table_list}")){
  492. while($row3 = $sql -> db_Fetch()){
  493. $field_name=$row3[0];
  494. $selected = ($curVals[2] == $field_name) ? " selected='selected' " : "";
  495. $text .="<option value=\"$field_name\" $selected>".$field_name."</option>\n";
  496. }
  497. }
  498. $text .= " </select></td></tr><tr><td>";
  499.  
  500. $text .= LAN_ORDER."</td><td><select style='width:99%' class='tbox' name='field_order' >
  501. <option value='' class='caption'>".EXTLAN_61."</option>\n";
  502. $table_list = ($_POST['table_db']) ? $_POST['table_db'] : $curVals[0] ;
  503. if($sql -> db_Select_gen("DESCRIBE ".MPREFIX."{$table_list}")){
  504. while($row3 = $sql -> db_Fetch()){
  505. $field_name=$row3[0];
  506. $selected = ($curVals[3] == $field_name) ? " selected='selected' " : "";
  507. $text .="<option value=\"$field_name\" $selected>".$field_name."</option>\n";
  508. }
  509. }
  510. $text .= " </select></td></tr>";
  511.  
  512. }
  513. $text .= "</table></div>";
  514. // ---------------------------------------------------------
  515. $text .= "
  516. </td>
  517. </tr>
  518.  
  519. <tr>
  520. <td style='width:30%;vertical-align:top' class='forumheader3'>".EXTLAN_16."</td>
  521. <td style='width:70%' class='forumheader3' colspan='3'>
  522. <input class='tbox' type='text' name='user_default' size='40' value='{$current['user_extended_struct_default']}' />
  523. </td>
  524. </tr>
  525.  
  526.  
  527. <tr>
  528. <td style='width:30%;vertical-align:top' class='forumheader3'>".EXTLAN_15."</td>
  529. <td style='width:70%' class='forumheader3' colspan='3'>
  530. <textarea class='tbox' name='user_include' cols='60' rows='2'>{$current_include}</textarea><br />
  531. <span class='smalltext'>".EXTLAN_51."</span><br />
  532. </td>
  533. </tr>
  534.  
  535. <tr>
  536. <td style='width:30%;vertical-align:top' class='forumheader3'>".EXTLAN_52."</td>
  537. <td style='width:70%' class='forumheader3' colspan='3'>
  538. <input class='tbox' type='text' name='user_regex' size='30' value='{$current_regex}' /><br />
  539. <span class='smalltext'>".EXTLAN_53."</span><br />
  540. </td>
  541. </tr>
  542.  
  543. <tr>
  544. <td style='width:30%;vertical-align:top' class='forumheader3'>".EXTLAN_54."</td>
  545. <td style='width:70%' class='forumheader3' colspan='3'>
  546. <input class='tbox' type='text' name='user_regexfail' size='40' value='{$current_regexfail}' /><br />
  547. <span class='smalltext'>".EXTLAN_55."</span><br />
  548. </td>
  549. </tr>
  550.  
  551. <tr>
  552. <td style='width:30%;vertical-align:top' class='forumheader3'>".EXTLAN_44."</td>
  553. <td style='width:70%' class='forumheader3' colspan='3'>
  554. <select class='tbox' name='user_parent'>";
  555. foreach($catNums as $k)
  556. {
  557. $sel = ($k == $current['user_extended_struct_parent']) ? " selected='selected' " : "";
  558. $text .= "<option value='{$k}' {$sel}>{$catList[$k][0]['user_extended_struct_name']}</option>\n";
  559. }
  560. $text .= "</select>
  561.  
  562. </td>
  563. </tr>
  564.  
  565. <tr>
  566. <td style='width:30%;vertical-align:top' class='forumheader3'>".EXTLAN_18."</td>
  567. <td style='width:70%' class='forumheader3' colspan='3'>
  568. <select class='tbox' name='user_required'>
  569. ";
  570. $_r = array('0' => EXTLAN_65, '1' => EXTLAN_66, '2' => EXTLAN_67);
  571. foreach($_r as $k => $v)
  572. {
  573. $sel = ($current['user_extended_struct_required'] == $k ? " selected='selected' " : "");
  574. $text .= "<option value='{$k}' {$sel}>{$v}</option>\n";
  575. }
  576.  
  577. $text .= "
  578. </select>
  579. <br />
  580. <span class='smalltext'>".EXTLAN_19."</span>
  581. </td>
  582. </tr>
  583.  
  584. <tr>
  585. <td style='width:30%;vertical-align:top' class='forumheader3'>".EXTLAN_5."</td>
  586. <td style='width:70%' class='forumheader3' colspan='3'>
  587. ".r_userclass("user_applicable", $current['user_extended_struct_applicable'], 'off', 'member, admin, classes, nobody')."<br /><span class='smalltext'>".EXTLAN_20."</span>
  588. </td>
  589. </tr>
  590.  
  591. <tr>
  592. <td style='width:30%;vertical-align:top' class='forumheader3'>".EXTLAN_6."</td>
  593. <td style='width:70%' class='forumheader3' colspan='3'>
  594. ".r_userclass("user_read", $current['user_extended_struct_read'], 'off', 'public, member, admin, readonly, classes')."<br /><span class='smalltext'>".EXTLAN_22."</span>
  595. </td>
  596. </tr>
  597.  
  598. <tr>
  599. <td style='width:30%;vertical-align:top' class='forumheader3'>".EXTLAN_7."</td>
  600. <td style='width:70%' class='forumheader3' colspan='3'>
  601. ".r_userclass("user_write", $current['user_extended_struct_write'], 'off', 'member, admin, classes')."<br /><span class='smalltext'>".EXTLAN_21."</span>
  602. </td>
  603. </tr>
  604.  
  605. <tr>
  606. <td style='width:30%;vertical-align:top' class='forumheader3'>".EXTLAN_49."
  607. </td>
  608. <td style='width:70%' class='forumheader3' colspan='3'>
  609. <select class='tbox' name='user_hide'>
  610. ";
  611. if($current_hide)
  612. {
  613. $text .= "
  614. <option value='1' selected='selected'>".LAN_YES."</option>
  615. <option value='0'>".LAN_NO."</option>";
  616. }
  617. else
  618. {
  619. $text .= "
  620. <option value='1'>".LAN_YES."</option>
  621. <option value='0' selected='selected'>".LAN_NO."</option>";
  622. }
  623. $text .= "
  624. </select>
  625. <br /><span class='smalltext'>".EXTLAN_50."</span>
  626. </td>
  627. </tr>
  628. ";
  629.  
  630. $text .= "<tr>
  631. <td colspan='4' style='text-align:center' class='forumheader'>";
  632.  
  633. // if ((!is_array($current) || $action == "continue") && $sub_action == "")
  634. if ((($mode == 'new') || $action == "continue") && $sub_action == "")
  635. {
  636. $text .= "
  637. <input class='button' type='submit' name='add_field' value='".EXTLAN_23."' />
  638. ";
  639. }
  640. else
  641. {
  642. $text .= "
  643. <input class='button' type='submit' name='update_field' value='".EXTLAN_24."' /> &nbsp; &nbsp;
  644. <input class='button' type='submit' name='cancel' value='".EXTLAN_33."' />
  645. ";
  646. }
  647. // ======= end added by Cam.
  648. $text .= "</td>
  649. </tr>
  650.  
  651. </table></form>
  652. ";
  653. }
  654. // $text .= "</div>";
  655. $ns->tablerender(EXTLAN_9, $text);
  656. }
  657.  
  658.  
  659. function show_categories($current)
  660. {
  661. global $sql, $ns, $ue;
  662.  
  663. $text = "<div style='text-align:center'>";
  664. $text .= "
  665. <table style='".ADMIN_WIDTH."' class='fborder'>
  666. <tr>
  667. <td class='fcaption'>".EXTLAN_1."</td>
  668. <td class='fcaption'>".EXTLAN_5."</td>
  669. <td class='fcaption'>".EXTLAN_6."</td>
  670. <td class='fcaption'>".EXTLAN_7."</td>
  671. <td class='fcaption'>&nbsp;</td>
  672. <td class='fcaption'>".EXTLAN_8."</td>
  673. </tr>
  674. ";
  675. $catList = $ue->user_extended_get_categories(FALSE);
  676. if(count($catList))
  677. {
  678. // Show current categories
  679. $i=0;
  680. foreach($catList as $ext)
  681. {
  682. if ($ext['user_extended_struct_order'] != $i)
  683. {
  684. $ext['user_extended_struct_order'] = $i;
  685. $xID=$ext['user_extended_struct_id'];
  686. $sql->db_Update("user_extended_struct", "user_extended_struct_order=$i WHERE user_extended_struct_type = 0 AND user_extended_struct_id=$xID");
  687. }
  688.  
  689. $text .= "
  690. <td class='forumheader3'>{$ext['user_extended_struct_name']}</td>
  691. </td>
  692. <td class='forumheader3'>".r_userclass_name($ext['user_extended_struct_applicable'])."</td>
  693. <td class='forumheader3'>".r_userclass_name($ext['user_extended_struct_read'])."</td>
  694. <td class='forumheader3'>".r_userclass_name($ext['user_extended_struct_write'])."</td>
  695. <td class='forumheader3'>
  696. <form method='post' action='".e_SELF."?cat'>
  697. <input type='hidden' name='id' value='{$ext['user_extended_struct_id']}.{$ext['user_extended_struct_order']}' />
  698. ";
  699. if($i > 0)
  700. {
  701. $text .= "
  702. <input type='image' alt='' title='".EXTLAN_26."' src='".e_IMAGE."/admin_images/up.png' name='catup' value='{$ext['user_extended_struct_id']}.{$i}' />
  703. ";
  704. }
  705. if($i <= count($catList)-2)
  706. {
  707. $text .= "<input type='image' alt='' title='".EXTLAN_25."' src='".e_IMAGE."/admin_images/down.png' name='catdown' value='{$ext['user_extended_struct_id']}.{$i}' />";
  708. }
  709. $text .= "
  710. </form>
  711. </td>
  712. <td class='forumheader3' style='text-align:center; white-space: nowrap'>
  713. <form method='post' action='".e_SELF."?cat' onsubmit='return confirm(\"".EXTLAN_27."\")'>
  714. <input type='hidden' name='eu_action' value='delcat' />
  715. <input type='hidden' name='key' value='{$ext['user_extended_struct_id']},{$ext['user_extended_struct_name']}' />
  716. <a style='text-decoration:none' href='".e_SELF."?cat.{$ext['user_extended_struct_id']}'>".ADMIN_EDIT_ICON."</a>
  717. <input type='image' title='".LAN_DELETE."' name='eudel' src='".ADMIN_DELETE_ICON_PATH."' />
  718. </form>
  719. </td>
  720. </tr>
  721. ";
  722. $i++;
  723. }
  724. }
  725. else
  726. {
  727. $text .= "
  728. <tr>
  729. <td colspan='8' class='forumheader3' style='text-align:center'>".EXTLAN_37."</td>
  730. </tr>
  731. ";
  732. }
  733.  
  734. //Show add/edit form
  735. $text .= "
  736. </table>
  737. <form method='post' action='".e_SELF."?".e_QUERY."'>
  738. ";
  739. $text .= "<div><br /></div><table style='".ADMIN_WIDTH."' class='fborder'> ";
  740. $text .= "
  741.  
  742. <tr>
  743. <td style='width:30%' class='forumheader3'>".EXTLAN_38.":</td>
  744. <td style='width:70%' class='forumheader3' colspan='3'>
  745. <input class='tbox' type='text' name='user_field' size='40' value='".$current['user_extended_struct_name']."' maxlength='50' />
  746. <br /><span class='smalltext'>".EXTLAN_11."</span>
  747. </td>
  748. </tr>
  749.  
  750. <tr>
  751. <td style='width:30%' class='forumheader3'>".EXTLAN_5."</td>
  752. <td style='width:70%' class='forumheader3' colspan='3'>
  753. ".r_userclass("user_applicable", $current['user_extended_struct_applicable'], 'off', 'member, admin, classes')."<br /><span class='smalltext'>".EXTLAN_20."</span>
  754. </td>
  755. </tr>
  756.  
  757. <tr>
  758. <td style='width:30%' class='forumheader3'>".EXTLAN_6."</td>
  759. <td style='width:70%' class='forumheader3' colspan='3'>
  760. ".r_userclass("user_read", $current['user_extended_struct_read'], 'off', 'public, member, admin, classes, readonly')."<br /><span class='smalltext'>".EXTLAN_22."</span>
  761. </td>
  762. </tr>
  763.  
  764. <tr>
  765. <td style='width:30%' class='forumheader3'>".EXTLAN_7."</td>
  766. <td style='width:70%' class='forumheader3' colspan='3'>
  767. ".r_userclass("user_write", $current['user_extended_struct_write'], 'off', 'member, admin, classes')."<br /><span class='smalltext'>".EXTLAN_21."</span>
  768. </td>
  769. </tr>";
  770.  
  771.  
  772. $text .= "<tr>
  773. <td colspan='4' style='text-align:center' class='forumheader'>";
  774.  
  775. if (!is_array($current))
  776. {
  777. $text .= "
  778. <input class='button' type='submit' name='add_category' value='".EXTLAN_39."' />
  779. ";
  780. }
  781. else
  782. {
  783. $text .= "
  784. <input class='button' type='submit' name='update_category' value='".EXTLAN_42."' /> &nbsp; &nbsp;
  785. <input class='button' type='submit' name='cancel_cat' value='".EXTLAN_33."' />
  786. ";
  787. }
  788. // ======= end added by Cam.
  789. $text .= "</td>
  790. </tr>
  791.  
  792. </table></form></div>";
  793. $ns->tablerender(EXTLAN_9, $text);
  794. }
  795.  
  796.  
  797. function show_options($action)
  798. {
  799. if ($action == "")
  800. {
  801. $action = "main";
  802. }
  803. $var['main']['text'] = EXTLAN_34;
  804. $var['main']['link'] = e_SELF;
  805.  
  806. $var['editext']['text'] = EXTLAN_45;
  807. $var['editext']['link'] = e_SELF."?editext";
  808.  
  809. $var['cat']['text'] = EXTLAN_35;
  810. $var['cat']['link'] = e_SELF."?cat";
  811.  
  812. $var['pre']['text'] = EXTLAN_56;
  813. $var['pre']['link'] = e_SELF."?pre";
  814.  
  815. show_admin_menu(EXTLAN_9, $action, $var);
  816. }
  817. }
  818.  
  819.  
  820. function users_extended_adminmenu() {
  821. global $user, $action, $ns, $curtype, $action;
  822. $user->show_options($action);
  823. if($action == 'editext' || $action == 'continue')
  824. {
  825. $ns->tablerender(EXTLAN_46." - <span id='ue_type'>&nbsp;</span>", "<div id='ue_help'>&nbsp;</div>");
  826. echo "<script type='text/javascript'>changeHelp('{$curtype}');</script>";
  827. }
  828. }
  829.  
  830.  
  831. function make_delimited($var)
  832. {
  833. global $tp;
  834. foreach($var as $k => $v)
  835. {
  836. $var[$k] = $tp->toDB(trim($v));
  837. $var[$k] = str_replace(",", "[E_COMMA]", $var[$k]);
  838. if($var[$k] == "")
  839. {
  840. unset($var[$k]);
  841. }
  842. }
  843. $ret = implode(",", $var);
  844. return $ret;
  845. }
  846.  
  847.  
  848. function show_predefined()
  849. {
  850. global $tp, $ns, $ue, $sql;
  851.  
  852. // Get list of current extended fields
  853. $curList = $ue->user_extended_get_fieldlist();
  854. foreach($curList as $c)
  855. {
  856. $curNames[] = $c['user_extended_struct_name'];
  857. }
  858.  
  859. //Get list of predefined fields, determine which are already activated.
  860. $preList = $ue->parse_extended_xml('getfile');
  861. ksort($preList);
  862. $active = array();
  863. foreach($preList as $k => $v)
  864. {
  865. if($k != 'version')
  866. {
  867. if(in_array($v['name'], $curNames))
  868. {
  869. $active[] = $v;
  870. }
  871. else
  872. {
  873. $inactive[] = $v;
  874. }
  875. }
  876. }
  877.  
  878. $txt = "
  879. <form method='post' action='".e_SELF."?pre'>
  880. <table class='fborder' style='".ADMIN_WIDTH."'>
  881. <tr>
  882. <td class='fcaption' colspan='4'>".EXTLAN_57."</td>
  883. </tr>
  884. ";
  885. if(count($active))
  886. {
  887. foreach($active as $a)
  888. {
  889. $txt .= show_field($a, 'deactivate');
  890. }
  891. }
  892. else
  893. {
  894. $txt .= "<tr><td class='forumheader3' colspan='4'>".EXTLAN_61."</td></tr>";
  895. }
  896.  
  897. $txt .= "
  898. <tr>
  899. <td class='fcaption' colspan='4'>".EXTLAN_58."</td>
  900. </tr>
  901. ";
  902. foreach($inactive as $a)
  903. {
  904. $txt .= show_field($a);
  905. }
  906. $txt .= "</table></form>";
  907. $ns->tablerender(EXTLAN_56, $txt);
  908. require_once('footer.php');
  909. exit;
  910. }
  911.  
  912.  
  913. function show_field($var, $type='activate')
  914. {
  915. global $tp;
  916. static $head_shown;
  917. $txt = "";
  918. // $showlist = array('type','text', 'values', 'include_text', 'regex');
  919. if($head_shown != 1)
  920. {
  921. $txt .= "
  922. <tr>
  923. <td class='forumheader'>".UE_LAN_9."</td>
  924. <td class='forumheader'>".UE_LAN_10."</td>
  925. <td class='forumheader'>".UE_LAN_11."</td>
  926. <td class='forumheader' style='width: 5%'>&nbsp;</td>
  927. </tr>
  928. ";
  929. $head_shown = 1;
  930. }
  931. $txt .= "
  932. <tr>
  933. <td class='forumheader3'>{$var['name']}</td>
  934. <td class='forumheader3'>".$tp->toHTML($var['type'], false, 'defs')."</td>
  935. <td class='forumheader3'>".constant(strtoupper($var['text'])."_DESC")."</td>
  936. ";
  937. // $txt .= constant("UE_LAN_".strtoupper($var['text'])."DESC")."<br />";
  938. // foreach($showlist as $f)
  939. // {
  940. // if($var[$f] != "" && $f != 'type' && $f !='text')
  941. // {
  942. // $txt .= "<strong>{$f}: </strong>".$tp->toHTML($var[$f], false, 'defs')."<br />";
  943. // }
  944. // }
  945. $val = ('activate' == $type) ? EXTLAN_59 : EXTLAN_60;
  946. $txt .= "
  947. <td class='forumheader3' style='text-align: center'><input class='button' type='submit' name='{$type}[{$var['name']}]' value='{$val}' /></td>
  948. </tr>";
  949. return $txt;
  950. }
  951.  
  952.  
  953. function field_activate()
  954. {
  955. global $ue, $ns, $tp;
  956. $ret = "";
  957. $preList = $ue->parse_extended_xml('getfile');
  958. $tmp = $preList;
  959.  
  960. foreach(array_keys($_POST['activate']) as $f)
  961. {
  962.  
  963. $tmp[$f]['parms'] = $tp->toDB($tmp[$f]['parms']);
  964. if($ue->user_extended_add($tmp[$f]))
  965. {
  966. $ret .= EXTLAN_68." $f ".EXTLAN_69."<br />";
  967.  
  968. if ($tmp[$f]['type']=="db field")
  969. {
  970. if (is_readable(e_ADMIN.'sql/extended_'.$f.'.php'))
  971. {
  972. $ret .= (process_sql($f)) ? LAN_CREATED." user_extended_{$f}<br />" : LAN_CREATED_FAILED." user_extended_{$f}<br />";
  973. }
  974. else
  975. {
  976. $ret .= str_replace('--FILE--',e_ADMIN.'sql/extended_'.$f.'.php',EXTLAN_78);
  977. }
  978. }
  979. }
  980. else
  981. {
  982. $ret .= EXTLAN_70." $f ".EXTLAN_71."<br />";
  983. }
  984. }
  985. return $ret;
  986. }
  987.  
  988.  
  989. function field_deactivate()
  990. {
  991. global $ue, $ns, $tp,$sql;
  992. $ret = "";
  993. foreach(array_keys($_POST['deactivate']) as $f)
  994. {
  995. if($ue->user_extended_remove($f, $f))
  996. {
  997. $ret .= EXTLAN_68." $f ".EXTLAN_72."<br />";
  998. if(is_readable(e_ADMIN."sql/extended_".$f.".php")){
  999. $ret .= (mysql_query("DROP TABLE ".MPREFIX."user_extended_".$f)) ? LAN_DELETED." user_extended_".$f."<br />" : LAN_DELETED_FAILED." user_extended_".$f."<br />";
  1000. }
  1001. }
  1002. else
  1003. {
  1004. $ret .= EXTLAN_70." $f ".EXTLAN_73."<br />";
  1005. }
  1006. }
  1007. return $ret;
  1008. }
  1009.  
  1010.  
  1011. function process_sql($f)
  1012. {
  1013. global $sql;
  1014. $filename = e_ADMIN."sql/extended_".$f.".php";
  1015. $fd = fopen ($filename, "r");
  1016. $sql_data = fread($fd, filesize($filename));
  1017. fclose ($fd);
  1018.  
  1019. $search[0] = "CREATE TABLE "; $replace[0] = "CREATE TABLE ".MPREFIX;
  1020. $search[1] = "INSERT INTO "; $replace[1] = "INSERT INTO ".MPREFIX;
  1021.  
  1022. preg_match_all("/create(.*?)myisam;/si", $sql_data, $creation);
  1023. foreach($creation[0] as $tab){
  1024. $query = str_replace($search,$replace,$tab);
  1025. if(!mysql_query($query)){
  1026. $error = TRUE;
  1027. }
  1028. }
  1029.  
  1030. preg_match_all("/insert(.*?);/si", $sql_data, $inserts);
  1031. foreach($inserts[0] as $ins){
  1032. $qry = str_replace($search,$replace,$ins);
  1033. if(!mysql_query($qry)){
  1034. $error = TRUE;
  1035. }
  1036. }
  1037.  
  1038. return ($error) ? FALSE : TRUE;
  1039.  
  1040. }
  1041.  
  1042.  
  1043.  
  1044. function headerjs()
  1045. {
  1046. include_once(e_LANGUAGEDIR.e_LANGUAGE."/lan_user_extended.php");
  1047. $text = "
  1048. <script type='text/javascript'>
  1049.  
  1050. function changeHelp(type) {
  1051. var ftype;
  1052. var helptext;
  1053. ";
  1054. for($i=1; $i<=12; $i++)
  1055. {
  1056. $type_const = "UE_LAN_{$i}";
  1057. $help_const = "EXTLAN_HELP_{$i}";
  1058. $text .= "
  1059. if(type == \"{$i}\")
  1060. {
  1061. xtype=\"".constant($type_const)."\";
  1062. what=\"".constant($help_const)."\";
  1063. }";
  1064. }
  1065. $text .= "
  1066. document.getElementById('ue_type').innerHTML=''+xtype+'';
  1067. document.getElementById('ue_help').innerHTML=''+what+'';
  1068.  
  1069. if(type == 4){
  1070. document.getElementById('db_mode').style.display = '';
  1071. document.getElementById('values').style.display = 'none';
  1072. }else{
  1073. document.getElementById('values').style.display = '';
  1074. document.getElementById('db_mode').style.display = 'none';
  1075. }
  1076. }
  1077.  
  1078.  
  1079. </script>";
  1080.  
  1081. global $cal;
  1082. $text .= $cal->load_files();
  1083.  
  1084. echo $text;
  1085. }
  1086. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement