PageRenderTime 119ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 2ms

/system/cp/cp.publish_ad.php

https://github.com/danboy/Croissierd
PHP | 9837 lines | 6347 code | 2490 blank | 1000 comment | 1050 complexity | cb9f56f24aac85e72e5f9a15660ae259 MD5 | raw file
  1. <?php
  2. /*
  3. =====================================================
  4. ExpressionEngine - by EllisLab
  5. -----------------------------------------------------
  6. http://expressionengine.com/
  7. -----------------------------------------------------
  8. Copyright (c) 2003 - 2010 EllisLab, Inc.
  9. =====================================================
  10. THIS IS COPYRIGHTED SOFTWARE
  11. PLEASE READ THE LICENSE AGREEMENT
  12. http://expressionengine.com/docs/license.html
  13. =====================================================
  14. File: cp.publish_ad.php
  15. -----------------------------------------------------
  16. Purpose: The publish administration functions
  17. =====================================================
  18. */
  19. if ( ! defined('EXT'))
  20. {
  21. exit('Invalid file request');
  22. }
  23. class PublishAdmin {
  24. var $reserved = array('random', 'date', 'title', 'url_title', 'edit_date', 'comment_total', 'username', 'screen_name', 'most_recent_comment', 'expiration_date');
  25. // Default "open" and "closed" status colors
  26. var $status_color_open = '009933';
  27. var $status_color_closed = '990000';
  28. // Category arrays
  29. var $categories = array();
  30. var $cat_update = array();
  31. var $temp;
  32. /** -----------------------------------------------------------
  33. /** Constructor
  34. /** -----------------------------------------------------------*/
  35. // All it does it fetch the language file needed by the class
  36. //-----------------------------------------------------------
  37. function PublishAdmin()
  38. {
  39. global $LANG, $DSP;
  40. // Fetch language file
  41. $LANG->fetch_language_file('publish_ad');
  42. }
  43. /* END */
  44. /** -----------------------------------------------------------
  45. /** Weblog management page
  46. /** -----------------------------------------------------------*/
  47. // This function displays the "weblog management" page
  48. // accessed via the "admin" tab
  49. //-----------------------------------------------------------
  50. function weblog_overview($message = '')
  51. {
  52. global $LANG, $DSP, $DB, $PREFS;
  53. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  54. {
  55. return $DSP->no_access_message();
  56. }
  57. $DSP->title = $LANG->line('weblog_management');
  58. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration'));
  59. $DSP->crumb .= $DSP->crumb_item($LANG->line('weblog_management'));
  60. $DSP->right_crumb($LANG->line('create_new_weblog'), BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=new_weblog');
  61. // Fetch weblogs
  62. $query = $DB->query("SELECT weblog_id, blog_name, blog_title FROM exp_weblogs WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND is_user_blog = 'n' ORDER BY blog_title");
  63. if ($query->num_rows == 0)
  64. {
  65. $DSP->body = $DSP->qdiv('tableHeading', $LANG->line('weblog_management'));
  66. $DSP->body .= $DSP->div('box');
  67. $DSP->body .= $DSP->qdiv('itemWrapper', $DSP->heading($LANG->line('no_weblogs_exist'), 5));
  68. $DSP->body .= $DSP->qdiv('itemWrapper', $DSP->anchor( BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=new_weblog', $LANG->line('create_new_weblog')));
  69. $DSP->body .= $DSP->div_c();
  70. return;
  71. }
  72. $r = $DSP->qdiv('tableHeading', $LANG->line('weblog_management'));
  73. if ($message != '')
  74. {
  75. $r .= $DSP->qdiv('box', stripslashes($message));
  76. }
  77. $r .= $DSP->table('tableBorder', '0', '', '100%');
  78. $r .= $DSP->tr().
  79. $DSP->td('tableHeadingAlt', '30px').$LANG->line('weblog_id').$DSP->td_c().
  80. $DSP->td('tableHeadingAlt').$LANG->line('weblog_name').$DSP->td_c().
  81. $DSP->td('tableHeadingAlt', '', '4').$LANG->line('weblog_short_name').$DSP->td_c().
  82. $DSP->tr_c();
  83. $i = 0;
  84. foreach($query->result as $row)
  85. {
  86. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  87. $r .= $DSP->tr();
  88. $r .= $DSP->table_qcell($style, $DSP->qspan('default', $row['weblog_id']));
  89. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $row['blog_title']).$DSP->nbs(5));
  90. $r .= $DSP->table_qcell($style, $DSP->qspan('default', $row['blog_name']).$DSP->nbs(5));
  91. $r .= $DSP->table_qcell($style,
  92. $DSP->anchor(
  93. BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=blog_prefs'.AMP.'weblog_id='.$row['weblog_id'],
  94. $LANG->line('edit_preferences')
  95. ));
  96. $r .= $DSP->table_qcell($style,
  97. $DSP->anchor(
  98. BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=group_prefs'.AMP.'weblog_id='.$row['weblog_id'],
  99. $LANG->line('edit_groups')
  100. ));
  101. $r .= $DSP->table_qcell($style,
  102. $DSP->anchor(
  103. BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=delete_conf'.AMP.'weblog_id='.$row['weblog_id'],
  104. $LANG->line('delete')
  105. ));
  106. $r .= $DSP->tr_c();
  107. }
  108. $r .= $DSP->table_c();
  109. // Assign output data
  110. $DSP->body = $r;
  111. }
  112. /* END */
  113. /** --------------------------------------------------------------
  114. /** "Create new weblog" form
  115. /** --------------------------------------------------------------*/
  116. // This function displays the form used to create a new weblog
  117. //--------------------------------------------------------------
  118. function new_weblog_form()
  119. {
  120. global $DSP, $IN, $DB, $REGX, $LANG, $FNS, $PREFS;
  121. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  122. {
  123. return $DSP->no_access_message();
  124. }
  125. $r = <<<EOT
  126. <script type="text/javascript">
  127. <!--
  128. function show_hide(id)
  129. {
  130. if (document.getElementById(id))
  131. {
  132. if (document.getElementById(id).style.display == 'none')
  133. {
  134. document.getElementById(id).style.display = 'block';
  135. }
  136. else
  137. {
  138. document.getElementById(id).style.display = 'none';
  139. }
  140. }
  141. }
  142. //-->
  143. </script>
  144. EOT;
  145. $r .= $DSP->form_open(array('action' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=create_blog'));
  146. $r .= $DSP->table('tableBorder', '0', '', '100%');
  147. $r .= $DSP->tr()
  148. .$DSP->td('tableHeading', '', '2').$LANG->line('create_new_weblog').$DSP->td_c()
  149. .$DSP->tr_c();
  150. // Weblog "full name" field
  151. $r .= $DSP->tr().
  152. $DSP->table_qcell('tableCellTwo', $DSP->required().NBS.$DSP->qspan('defaultBold', $LANG->line('full_weblog_name', 'blog_title'))).
  153. $DSP->table_qcell('tableCellTwo', $DSP->input_text('blog_title', '', '20', '100', 'input', '260px')).
  154. $DSP->tr_c();
  155. // Weblog "short name" field
  156. $r .= $DSP->tr().
  157. $DSP->table_qcell('tableCellOne', $DSP->required().NBS.$DSP->qspan('defaultBold', $LANG->line('short_weblog_name', 'blog_name')).$DSP->qdiv('', $LANG->line('single_word_no_spaces')), '40%').
  158. $DSP->table_qcell('tableCellOne', $DSP->input_text('blog_name', '', '20', '40', 'input', '260px'), '60%').
  159. $DSP->tr_c();
  160. // Duplicate Preferences Select List
  161. $r .= $DSP->tr().
  162. $DSP->table_qcell('tableCellTwo', $DSP->qspan('defaultBold', $LANG->line('duplicate_weblog_prefs')));
  163. $w = $DSP->input_select_header('duplicate_weblog_prefs');
  164. $w .= $DSP->input_select_option('', $LANG->line('do_not_duplicate'));
  165. $wquery = $DB->query("SELECT weblog_id, blog_title FROM exp_weblogs WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' ORDER BY blog_name");
  166. if ($wquery->num_rows > 0)
  167. {
  168. foreach($wquery->result as $row)
  169. {
  170. $w .= $DSP->input_select_option($row['weblog_id'], $row['blog_title']);
  171. }
  172. }
  173. $w .= $DSP->input_select_footer();
  174. $r .= $DSP->table_qcell('tableCellTwo', $w).
  175. $DSP->tr_c();
  176. // Edit Group Preferences option
  177. $r .= $DSP->tr().
  178. $DSP->table_qcell('tableCellOne', $DSP->qspan('defaultBold', $LANG->line('edit_group_prefs')), '40%').
  179. $DSP->table_qcell('tableCellOne', $DSP->input_radio('edit_group_prefs', 'y', '', 'onclick="show_hide(\'group_preferences\');"').
  180. NBS.$LANG->line('yes').
  181. NBS.NBS.
  182. $DSP->input_radio('edit_group_prefs', 'n', 1, 'onclick="show_hide(\'group_preferences\');"').
  183. NBS.$LANG->line('no'), '60%').
  184. $DSP->tr_c();
  185. $r .= $DSP->table_c().BR;
  186. // GROUP FIELDS
  187. $g = '';
  188. $i = 0;
  189. $cat_group = '';
  190. $status_group = '';
  191. $field_group = '';
  192. $r .= $DSP->div('', '', 'group_preferences', '', 'style="display:none;"');
  193. $r .= $DSP->table('tableBorder', '0', '', '100%');
  194. $r .= $DSP->tr().
  195. $DSP->td('tableHeadingAlt', '100%', 2).$LANG->line('edit_group_prefs').$DSP->td_c().
  196. $DSP->tr_c();
  197. // Category group select list
  198. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  199. $query = $DB->query("SELECT group_id, group_name FROM exp_category_groups WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' ORDER BY group_name");
  200. $g .= $DSP->tr().
  201. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('category_group')), '40%', 'top');
  202. $g .= $DSP->td($style).
  203. $DSP->input_select_header('cat_group[]', ($query->num_rows > 0) ? 'y' : '');
  204. $selected = '';
  205. $g .= $DSP->input_select_option('', $LANG->line('none'), $selected);
  206. if ($query->num_rows > 0)
  207. {
  208. foreach ($query->result as $row)
  209. {
  210. $g .= $DSP->input_select_option($row['group_id'], $row['group_name']);
  211. }
  212. }
  213. $g .= $DSP->input_select_footer().
  214. $DSP->td_c().
  215. $DSP->tr_c();
  216. // Status group select list
  217. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  218. $query = $DB->query("SELECT group_id, group_name FROM exp_status_groups WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' ORDER BY group_name");
  219. $g .= $DSP->tr().
  220. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('status_group')));
  221. $g .= $DSP->td($style).
  222. $DSP->input_select_header('status_group');
  223. $selected = '';
  224. $g .= $DSP->input_select_option('', $LANG->line('none'), $selected);
  225. if ($query->num_rows > 0)
  226. {
  227. foreach ($query->result as $row)
  228. {
  229. $selected = ($status_group == $row['group_id']) ? 1 : '';
  230. $g .= $DSP->input_select_option($row['group_id'], $row['group_name'], $selected);
  231. }
  232. }
  233. $g .= $DSP->input_select_footer().
  234. $DSP->td_c().
  235. $DSP->tr_c();
  236. // Field group select list
  237. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  238. $query = $DB->query("SELECT group_id, group_name FROM exp_field_groups WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' ORDER BY group_name");
  239. $g .= $DSP->tr().
  240. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('field_group')));
  241. $g .= $DSP->td($style).
  242. $DSP->input_select_header('field_group');
  243. $selected = '';
  244. $g .= $DSP->input_select_option('', $LANG->line('none'), $selected);
  245. if ($query->num_rows > 0)
  246. {
  247. foreach ($query->result as $row)
  248. {
  249. $selected = ($field_group == $row['group_id']) ? 1 : '';
  250. $g .= $DSP->input_select_option($row['group_id'], $row['group_name'], $selected);
  251. }
  252. }
  253. $g .= $DSP->input_select_footer().
  254. $DSP->td_c().
  255. $DSP->tr_c().
  256. $DSP->table_c().BR.
  257. $DSP->div_c();
  258. $r .= $g;
  259. // Table end
  260. // Create Template
  261. if ($DSP->allowed_group('can_admin_templates'))
  262. {
  263. $r .= $DSP->table('tableBorder', '0', '', '100%')
  264. .$DSP->tr()
  265. .$DSP->td('tableHeadingAlt', '', '3').$LANG->line('template_creation').$DSP->td_c()
  266. .$DSP->tr_c();
  267. $r .= $DSP->tr()
  268. .$DSP->table_qcell('tableCellOne', $DSP->input_radio('create_templates', 'no', 1), '2%')
  269. .$DSP->td('tableCellOne', '', '3').$DSP->qdiv('defaultBold', $LANG->line('no')).$DSP->td_c()
  270. .$DSP->tr_c();
  271. $data = $FNS->create_directory_map(PATH_THEMES.'site_themes/', TRUE);
  272. $d = '&nbsp;';
  273. if (count($data) > 0)
  274. {
  275. $d = $DSP->input_select_header('template_theme');
  276. foreach ($data as $val)
  277. {
  278. if ($val == 'rss.php')
  279. continue;
  280. if ( ! file_exists(PATH_THEMES.'site_themes/'.$val.'/'.$val.'.php'))
  281. {
  282. continue;
  283. }
  284. $nval = str_replace("_", " ", $val);
  285. $nval = ucwords($nval);
  286. $d .= $DSP->input_select_option($val, $nval);
  287. }
  288. $d .= $DSP->input_select_footer();
  289. }
  290. $r .= $DSP->tr()
  291. .$DSP->table_qcell('tableCellTwo', $DSP->input_radio('create_templates', 'theme', ''), '2%', 'top')
  292. .$DSP->table_qcell('tableCellTwo', $DSP->qdiv('defaultBold', $LANG->line('use_a_theme'), '38%')
  293. .$DSP->qdiv('itemWrapper',$DSP->input_checkbox('add_rss', 'y', 0).' '.$LANG->line('include_rss_templates')))
  294. .$DSP->table_qcell('tableCellTwo', $d, '60%')
  295. .$DSP->tr_c();
  296. $sql = "SELECT group_id, group_name, exp_sites.site_label
  297. FROM exp_template_groups, exp_sites
  298. WHERE exp_template_groups.site_id = exp_sites.site_id ";
  299. if ($PREFS->ini('multiple_sites_enabled') !== 'y')
  300. {
  301. $sql .= "AND exp_template_groups.site_id = '1' ";
  302. }
  303. if (USER_BLOG == TRUE)
  304. {
  305. $sql .= "AND exp_template_groups.group_id = '".$SESS->userdata['tmpl_group_id']."'";
  306. }
  307. else
  308. {
  309. $sql .= "AND exp_template_groups.is_user_blog = 'n'";
  310. }
  311. $sql .= " ORDER BY exp_template_groups.group_name";
  312. $query = $DB->query($sql);
  313. $d = $DSP->input_select_header('old_group_id');
  314. foreach ($query->result as $row)
  315. {
  316. $d .= $DSP->input_select_option($row['group_id'], ($PREFS->ini('multiple_sites_enabled') == 'y') ? $row['site_label'].NBS.'-'.NBS.$row['group_name'] : $row['group_name']);
  317. }
  318. $d .= $DSP->input_select_footer();
  319. $r .= $DSP->tr()
  320. .$DSP->table_qcell('tableCellOne', $DSP->input_radio('create_templates', 'duplicate', ''))
  321. .$DSP->table_qcell('tableCellOne', $DSP->qdiv('defaultBold', $LANG->line('duplicate_group')))
  322. .$DSP->table_qcell('tableCellOne', $d)
  323. .$DSP->tr_c();
  324. $r .= $DSP->tr()
  325. .$DSP->table_qcell('tableCellTwo', NBS)
  326. .$DSP->table_qcell('tableCellTwo', $DSP->qdiv('defaultBold', $DSP->required().$LANG->line('template_group_name')).$DSP->qdiv('', $LANG->line('new_group_instructions')).$DSP->qdiv('', $LANG->line('single_word_no_spaces')))
  327. .$DSP->td('tableCellTwo', '', '').$DSP->input_text('group_name', '', '16', '50', 'input', '130px').$DSP->td_c()
  328. .$DSP->tr_c();
  329. $r .= $DSP->table_c();
  330. }
  331. // Submit button
  332. $r .= $DSP->qdiv('itemWrapper', $DSP->required(1));
  333. $r .= $DSP->qdiv('', $DSP->input_submit($LANG->line('submit')));
  334. $r .= $DSP->form_close();
  335. // Assign output data
  336. $DSP->title = $LANG->line('create_new_weblog');
  337. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  338. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=blog_list', $LANG->line('weblog_management'))).
  339. $DSP->crumb_item($LANG->line('new_weblog'));
  340. $DSP->body = $r;
  341. }
  342. /* END */
  343. /** -----------------------------------------------------------
  344. /** Weblog preference submission handler
  345. /** -----------------------------------------------------------*/
  346. // This function receives the submitted weblog preferences
  347. // and stores them in the database.
  348. //-----------------------------------------------------------
  349. function update_weblog_prefs()
  350. {
  351. global $DSP, $IN, $DB, $LOG, $LANG, $FNS, $PREFS, $SESS, $LOC;
  352. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  353. {
  354. return $DSP->no_access_message();
  355. }
  356. // If the $weblog_id variable is present we are editing an
  357. // existing weblog, otherwise we are creating a new one
  358. $edit = (isset($_POST['weblog_id'])) ? TRUE : FALSE;
  359. $add_rss = (isset($_POST['add_rss'])) ? TRUE : FALSE;
  360. unset($_POST['add_rss']);
  361. $return = ($IN->GBL('return')) ? TRUE : FALSE;
  362. unset($_POST['return']);
  363. unset($_POST['edit_group_prefs']);
  364. $dupe_id = $IN->GBL('duplicate_weblog_prefs');
  365. unset($_POST['duplicate_weblog_prefs']);
  366. // Check for required fields
  367. $error = array();
  368. if ($_POST['blog_name'] == '')
  369. {
  370. $error[] = $LANG->line('no_weblog_name');
  371. }
  372. if ($_POST['blog_title'] == '')
  373. {
  374. $error[] = $LANG->line('no_weblog_title');
  375. }
  376. if (preg_match('/[^a-z0-9\-\_]/i', $_POST['blog_name']))
  377. {
  378. $error[] = $LANG->line('invalid_short_name');
  379. }
  380. if (isset($_POST['url_title_prefix']) && $_POST['url_title_prefix'] != '')
  381. {
  382. $_POST['url_title_prefix'] = strtolower(strip_tags($_POST['url_title_prefix']));
  383. if ( ! preg_match("/^[\w\-]+$/", $_POST['url_title_prefix']))
  384. {
  385. $error[] = $LANG->line('invalid_url_title_prefix');
  386. }
  387. }
  388. if (count($error) > 0)
  389. {
  390. $msg = '';
  391. foreach($error as $val)
  392. {
  393. $msg .= $val.BR;
  394. }
  395. return $DSP->error_message($msg);
  396. }
  397. if (isset($_POST['comment_expiration']))
  398. {
  399. if ( ! is_numeric($_POST['comment_expiration']) || $_POST['comment_expiration'] == '')
  400. {
  401. $_POST['comment_expiration'] = 0;
  402. }
  403. }
  404. // Is the weblog name taken?
  405. $sql = "SELECT COUNT(*) AS count FROM exp_weblogs WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND blog_name = '".$DB->escape_str($_POST['blog_name'])."'";
  406. if ($edit == TRUE)
  407. {
  408. $sql .= " AND weblog_id != '".$DB->escape_str($_POST['weblog_id'])."'";
  409. }
  410. $query = $DB->query($sql);
  411. if ($query->row['count'] > 0)
  412. {
  413. return $DSP->error_message($LANG->line('taken_weblog_name'));
  414. }
  415. /** -----------------------------------------
  416. /** Template Error Trapping
  417. /** -----------------------------------------*/
  418. if ($edit == FALSE)
  419. {
  420. $create_templates = $IN->GBL('create_templates');
  421. $old_group_id = $IN->GBL('old_group_id');
  422. $group_name = strtolower($IN->GBL('group_name', 'POST'));
  423. $template_theme = $FNS->filename_security($IN->GBL('template_theme'));
  424. unset($_POST['create_templates']);
  425. unset($_POST['old_group_id']);
  426. unset($_POST['group_name']);
  427. unset($_POST['template_theme']);
  428. if ($create_templates != 'no')
  429. {
  430. $LANG->fetch_language_file('templates');
  431. if ( ! $DSP->allowed_group('can_admin_templates'))
  432. {
  433. return $DSP->no_access_message();
  434. }
  435. if ( ! $group_name)
  436. {
  437. return $DSP->error_message($LANG->line('group_required'));
  438. }
  439. if ( ! preg_match("#^[a-zA-Z0-9_\-/]+$#i", $group_name))
  440. {
  441. return $DSP->error_message($LANG->line('illegal_characters'));
  442. }
  443. $reserved[] = 'act';
  444. $reserved[] = 'trackback';
  445. if ($PREFS->ini("forum_is_installed") == 'y' AND $PREFS->ini("forum_trigger") != '')
  446. {
  447. $reserved[] = $PREFS->ini("forum_trigger");
  448. }
  449. if (in_array($group_name, $reserved))
  450. {
  451. return $DSP->error_message($LANG->line('reserved_name'));
  452. }
  453. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_template_groups
  454. WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'
  455. AND group_name = '".$DB->escape_str($group_name)."'");
  456. if ($query->row['count'] > 0)
  457. {
  458. return $DSP->error_message($LANG->line('template_group_taken'));
  459. }
  460. }
  461. }
  462. /** -----------------------------------------
  463. /** Create Weblog
  464. /** -----------------------------------------*/
  465. // Construct the query based on whether we are updating or inserting
  466. if (isset($_POST['apply_expiration_to_existing']))
  467. {
  468. $this->update_comment_expiration($_POST['weblog_id'], $_POST['comment_expiration']);
  469. }
  470. unset($_POST['apply_expiration_to_existing']);
  471. if (isset($_POST['cat_group']) && is_array($_POST['cat_group']))
  472. {
  473. foreach($_POST['cat_group'] as $key => $value)
  474. {
  475. unset($_POST['cat_group_'.$key]);
  476. }
  477. $_POST['cat_group'] = implode('|', $_POST['cat_group']);
  478. }
  479. if ($edit == FALSE)
  480. {
  481. unset($_POST['weblog_id']);
  482. unset($_POST['clear_versioning_data']);
  483. $_POST['blog_url'] = $FNS->fetch_site_index();
  484. $_POST['blog_lang'] = $PREFS->ini('xml_lang');
  485. $_POST['blog_encoding'] = $PREFS->ini('charset');
  486. // Assign field group if there is only one
  487. if ( ! isset($_POST['field_group']) OR (isset($_POST['field_group']) && ! is_numeric($_POST['field_group'])))
  488. {
  489. $query = $DB->query("SELECT group_id FROM exp_field_groups WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'");
  490. if ($query->num_rows == 1)
  491. {
  492. $_POST['field_group'] = $query->row['group_id'];
  493. }
  494. }
  495. // Insert data
  496. $_POST['site_id'] = $PREFS->ini('site_id');
  497. // duplicating preferences?
  498. if ($dupe_id !== FALSE AND is_numeric($dupe_id))
  499. {
  500. $wquery = $DB->query("SELECT * FROM exp_weblogs WHERE weblog_id = '".$DB->escape_str($dupe_id)."'");
  501. if ($wquery->num_rows == 1)
  502. {
  503. $exceptions = array('weblog_id', 'site_id', 'blog_name', 'blog_title', 'total_entries',
  504. 'total_comments', 'total_trackbacks', 'last_entry_date', 'last_comment_date',
  505. 'last_trackback_date');
  506. foreach($wquery->row as $key => $val)
  507. {
  508. // don't duplicate fields that are unique to each weblog
  509. if (! in_array($key, $exceptions))
  510. {
  511. switch ($key)
  512. {
  513. // category, field, and status fields should only be duped
  514. // if both weblogs are assigned to the same group of each
  515. case 'cat_group':
  516. // allow to implicitly set category group to "None"
  517. if (! isset($_POST[$key]))
  518. {
  519. $_POST[$key] = $val;
  520. }
  521. break;
  522. case 'status_group':
  523. case 'field_group':
  524. if (! isset($_POST[$key]) OR $_POST[$key] == '')
  525. {
  526. $_POST[$key] = $val;
  527. }
  528. break;
  529. case 'deft_status':
  530. if (! isset($_POST['status_group']) OR $_POST['status_group'] == $wquery->row['status_group'])
  531. {
  532. $_POST[$key] = $val;
  533. }
  534. break;
  535. case 'search_excerpt':
  536. if (! isset($_POST['field_group']) OR $_POST['field_group'] == $wquery->row['field_group'])
  537. {
  538. $_POST[$key] = $val;
  539. }
  540. break;
  541. case 'deft_category':
  542. if (! isset($_POST['cat_group']) OR count(array_diff(explode('|', $_POST['cat_group']), explode('|', $wquery->row['cat_group']))) == 0)
  543. {
  544. $_POST[$key] = $val;
  545. }
  546. break;
  547. case 'blog_url':
  548. case 'comment_url':
  549. case 'search_results_url':
  550. case 'tb_return_url':
  551. case 'ping_return_url':
  552. case 'rss_url':
  553. if ($create_templates != 'no')
  554. {
  555. if ( ! isset($old_group_name))
  556. {
  557. $gquery = $DB->query("SELECT group_name FROM exp_template_groups WHERE group_id = '".$DB->escape_str($old_group_id)."'");
  558. $old_group_name = $gquery->row['group_name'];
  559. }
  560. $_POST[$key] = str_replace("/{$old_group_name}/", "/{$group_name}/", $val);
  561. }
  562. else
  563. {
  564. $_POST[$key] = $val;
  565. }
  566. break;
  567. default :
  568. $_POST[$key] = $val;
  569. break;
  570. }
  571. }
  572. }
  573. }
  574. }
  575. $sql = $DB->insert_string('exp_weblogs', $_POST);
  576. $DB->query($sql);
  577. $insert_id = $DB->insert_id;
  578. $weblog_id = $insert_id;
  579. $success_msg = $LANG->line('weblog_created');
  580. $crumb = $DSP->crumb_item($LANG->line('new_weblog'));
  581. $LOG->log_action($success_msg.$DSP->nbs(2).$_POST['blog_title']);
  582. }
  583. else
  584. {
  585. if (isset($_POST['clear_versioning_data']))
  586. {
  587. $DB->query("DELETE FROM exp_entry_versioning WHERE weblog_id = '".$DB->escape_str($_POST['weblog_id'])."'");
  588. unset($_POST['clear_versioning_data']);
  589. }
  590. $sql = $DB->update_string('exp_weblogs', $_POST, 'weblog_id='.$DB->escape_str($_POST['weblog_id']));
  591. $DB->query($sql);
  592. $weblog_id = $DB->escape_str($_POST['weblog_id']);
  593. $success_msg = $LANG->line('weblog_updated');
  594. $crumb = $DSP->crumb_item($LANG->line('update'));
  595. }
  596. /** -----------------------------------------
  597. /** Create Templates
  598. /** -----------------------------------------*/
  599. if ($edit == FALSE)
  600. {
  601. if ($create_templates != 'no')
  602. {
  603. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_template_groups WHERE is_user_blog = 'n'");
  604. $group_order = $query->row['count'] +1;
  605. $DB->query(
  606. $DB->insert_string(
  607. 'exp_template_groups',
  608. array(
  609. 'group_id' => '',
  610. 'group_name' => $group_name,
  611. 'group_order' => $group_order,
  612. 'is_site_default' => 'n',
  613. 'site_id' => $PREFS->ini('site_id')
  614. )
  615. )
  616. );
  617. $group_id = $DB->insert_id;
  618. if ($create_templates == 'duplicate')
  619. {
  620. $query = $DB->query("SELECT group_name FROM exp_template_groups WHERE group_id = '".$DB->escape_str($old_group_id)."'");
  621. $old_group_name = $query->row['group_name'];
  622. $query = $DB->query("SELECT template_name, template_data, template_type, template_notes, cache, refresh, no_auth_bounce, allow_php, php_parse_location FROM exp_templates WHERE group_id = '".$DB->escape_str($old_group_id)."'");
  623. if ($query->num_rows == 0)
  624. {
  625. $DB->query(
  626. $DB->insert_string(
  627. 'exp_templates',
  628. array(
  629. 'template_id' => '',
  630. 'group_id' => $group_id,
  631. 'template_name' => 'index',
  632. 'edit_date' => $LOC->now,
  633. 'site_id' => $PREFS->ini('site_id')
  634. )
  635. )
  636. );
  637. }
  638. else
  639. {
  640. $old_blog_name = '';
  641. foreach ($query->result as $row)
  642. {
  643. if ($old_blog_name == '')
  644. {
  645. if (preg_match_all("/weblog=[\"'](.+?)[\"']/", $row['template_data'], $matches))
  646. {
  647. for ($i = 0; $i < count($matches['1']); $i++)
  648. {
  649. if (substr($matches['1'][$i], 0, 1) != '{')
  650. {
  651. $old_blog_name = $matches['1'][$i];
  652. break;
  653. }
  654. }
  655. }
  656. }
  657. $temp = str_replace('weblog="'.$old_blog_name.'"', 'weblog="'.$_POST['blog_name'].'"', $row['template_data']);
  658. $temp = str_replace("weblog='".$old_blog_name."'", 'weblog="'.$_POST['blog_name'].'"', $temp);
  659. $temp = preg_replace("/{stylesheet=.+?\/(.+?)}/", "{stylesheet=".$group_name."/\\1}", $temp);
  660. $temp = preg_replace("#assign_variable:master_weblog_name=\".+?\"#", 'assign_variable:master_weblog_name="'.$_POST['blog_name'].'"', $temp);
  661. $temp = preg_replace("#assign_variable:master_weblog_name=\'.+?\'#", "assign_variable:master_weblog_name='".$_POST['blog_name']."'", $temp);
  662. $temp = preg_replace('#assign_variable:my_template_group=(\042|\047)([^\\1]*?)\\1#', "assign_variable:my_template_group=\\1{$group_name}\\1", $temp);
  663. $temp = preg_replace("#".$old_group_name."/(.+?)#", $group_name."/\\1", $temp);
  664. $data = array(
  665. 'template_id' => '',
  666. 'group_id' => $group_id,
  667. 'template_name' => $row['template_name'],
  668. 'template_notes' => $row['template_notes'],
  669. 'cache' => $row['cache'],
  670. 'refresh' => $row['refresh'],
  671. 'no_auth_bounce' => $row['no_auth_bounce'],
  672. 'php_parse_location' => $row['php_parse_location'],
  673. 'allow_php' => ($SESS->userdata['group_id'] == 1) ? $row['allow_php'] : 'n',
  674. 'template_type' => $row['template_type'],
  675. 'template_data' => $temp,
  676. 'edit_date' => $LOC->now,
  677. 'site_id' => $PREFS->ini('site_id')
  678. );
  679. $DB->query($DB->insert_string('exp_templates', $data));
  680. }
  681. }
  682. }
  683. else
  684. {
  685. $type = 'core';
  686. if ($fp = @opendir(PATH_MOD))
  687. {
  688. while (false !== ($file = readdir($fp)))
  689. {
  690. if (strpos($file, '.') === FALSE)
  691. {
  692. if ($file == 'mailinglist')
  693. {
  694. $type = 'full';
  695. break;
  696. }
  697. }
  698. }
  699. closedir($fp);
  700. }
  701. require PATH_THEMES.'site_themes/'.$template_theme.'/'.$template_theme.'.php';
  702. foreach ($template_matrix as $tmpl)
  703. {
  704. $Q[] = array($tmpl['0'](), "INSERT INTO exp_templates(template_id, group_id, template_name, template_type, template_data, edit_date, site_id)
  705. VALUES ('', '$group_id', '".$DB->escape_str($tmpl['0'])."', '".$DB->escape_str($tmpl['1'])."', '{template}', '".$LOC->now."', '".$DB->escape_str($PREFS->ini('site_id'))."')");
  706. }
  707. if ($add_rss == TRUE)
  708. {
  709. require PATH_THEMES.'site_themes/rss/rss.php';
  710. $Q[] = array(rss_2(), "INSERT INTO exp_templates(template_id, group_id, template_name, template_type, template_data, edit_date, site_id)
  711. VALUES ('', '$group_id', 'rss_2.0', 'rss', '{template}', '".$DB->escape_str($LOC->now)."', '".$DB->escape_str($PREFS->ini('site_id'))."')");
  712. $Q[] = array(atom(), "INSERT INTO exp_templates(template_id, group_id, template_name, template_type, template_data, edit_date, site_id)
  713. VALUES ('', '$group_id', 'atom', 'rss', '{template}', '".$DB->escape_str($LOC->now)."', '".$DB->escape_str($PREFS->ini('site_id'))."')");
  714. }
  715. foreach ($Q as $val)
  716. {
  717. $temp = $val['0'];
  718. $temp = str_replace('weblog="weblog1"', 'weblog="'.$_POST['blog_name'].'"', $temp);
  719. $temp = str_replace("weblog='weblog1'", 'weblog="'.$_POST['blog_name'].'"', $temp);
  720. $temp = str_replace('my_weblog="weblog1"', 'my_weblog="'.$_POST['blog_name'].'"', $temp);
  721. $temp = str_replace("my_weblog='weblog1'", 'my_weblog="'.$_POST['blog_name'].'"', $temp);
  722. $temp = str_replace('weblog="default_site"', 'weblog="'.$_POST['blog_name'].'"', $temp);
  723. $temp = str_replace("weblog='default_site'", 'weblog="'.$_POST['blog_name'].'"', $temp);
  724. $temp = str_replace('my_weblog="default_site"', 'my_weblog="'.$_POST['blog_name'].'"', $temp);
  725. $temp = str_replace("my_weblog='default_site'", 'my_weblog="'.$_POST['blog_name'].'"', $temp);
  726. $temp = str_replace('my_template_group="site"', 'my_template_group="'.$group_name.'"', $temp);
  727. $temp = str_replace("my_template_group='site'", 'my_template_group="'.$group_name.'"', $temp);
  728. $temp = str_replace("{stylesheet=weblog/weblog_css}", "{stylesheet=".$group_name."/site_css}", $temp);
  729. $temp = str_replace("{stylesheet=site/site_css}", "{stylesheet=".$group_name."/site_css}", $temp);
  730. $temp = str_replace('assign_variable:master_weblog_name="weblog1"', 'assign_variable:master_weblog_name="'.$_POST['blog_name'].'"', $temp);
  731. $temp = preg_replace("#weblog/(.+?)#", $group_name."/\\1", $temp);
  732. $temp = addslashes($temp);
  733. $sql = str_replace('{template}', $temp, $val['1']);
  734. $DB->query($sql);
  735. }
  736. }
  737. }
  738. }
  739. $message = $DSP->qdiv('itemWrapper', $DSP->qspan('success', $success_msg).NBS.NBS.'<b>'.$_POST['blog_title'].'</b>');
  740. if ($edit == FALSE OR $return === TRUE)
  741. return $this->weblog_overview($message);
  742. else
  743. return $this->edit_blog_form($message, $weblog_id);
  744. }
  745. /* END */
  746. /** -------------------------------------------
  747. /** Update weblog entries with comment expiration
  748. /** -------------------------------------------*/
  749. function update_comment_expiration($weblog_id = '', $expiration = '')
  750. {
  751. global $DSP, $IN, $DB, $LOG, $LANG, $FNS, $PREF;
  752. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  753. {
  754. return $DSP->no_access_message();
  755. }
  756. if ($weblog_id == '')
  757. {
  758. return FALSE;
  759. }
  760. if ($expiration == '')
  761. $expiration = 0;
  762. $time = $expiration * 86400;
  763. $expdate = '';
  764. $query = $DB->query("SELECT entry_id, entry_date FROM exp_weblog_titles WHERE weblog_id = '".$DB->escape_str($weblog_id)."'");
  765. if ($query->num_rows > 0)
  766. {
  767. foreach ($query->result as $row)
  768. {
  769. if ($expiration > 0)
  770. {
  771. $expdate = $row['entry_date'] + $time;
  772. }
  773. $DB->query("UPDATE exp_weblog_titles SET comment_expiration_date = '$expdate' WHERE entry_id = '".$DB->escape_str($row['entry_id'])."'");
  774. }
  775. }
  776. return;
  777. }
  778. /* END */
  779. /** -------------------------------------------
  780. /** Create pull-down optios from dirctory map
  781. /** -------------------------------------------*/
  782. function render_map_as_select_options($zarray, $array_name = '')
  783. {
  784. foreach ($zarray as $key => $val)
  785. {
  786. if ( is_array($val))
  787. {
  788. if ($array_name != "")
  789. $key = $array_name.'/'.$key;
  790. $this->render_map_as_select_options($val, $key);
  791. }
  792. else
  793. {
  794. if ($array_name <> "")
  795. $val = $array_name.'/'.$val;
  796. if (substr($val, -4) == '.php')
  797. {
  798. if ($val != 'theme_master.php')
  799. {
  800. $this->template_map[] = $val;
  801. }
  802. }
  803. }
  804. }
  805. }
  806. /* END */
  807. /** -----------------------------------------------------------
  808. /** Weblog preferences form
  809. /** -----------------------------------------------------------*/
  810. // This function displays the form used to edit the various
  811. // preferences for a given weblog
  812. //-----------------------------------------------------------
  813. function edit_blog_form($msg='', $weblog_id='')
  814. {
  815. global $DSP, $IN, $DB, $REGX, $LANG, $FNS, $PREFS;
  816. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  817. {
  818. return $DSP->no_access_message();
  819. }
  820. // Set default values
  821. $i = 0;
  822. $blog_name = '';
  823. $blog_title = '';
  824. $cat_group = '';
  825. $status_group = '';
  826. // If we don't have the $weblog_id variable, bail out.
  827. if ($weblog_id == '')
  828. {
  829. if ( ! $weblog_id = $IN->GBL('weblog_id'))
  830. {
  831. return FALSE;
  832. }
  833. }
  834. if ( ! is_numeric($weblog_id))
  835. {
  836. return FALSE;
  837. }
  838. $query = $DB->query("SELECT * FROM exp_weblogs WHERE weblog_id = '$weblog_id'");
  839. foreach ($query->row as $key => $val)
  840. {
  841. $$key = $val;
  842. }
  843. if ($msg != '')
  844. {
  845. $DSP->body .= $DSP->qdiv('box', $msg);
  846. }
  847. $DSP->body_props .= ' onload="showHideMenu(\'weblog\');"';
  848. // Build the output
  849. ob_start();
  850. ?>
  851. <script type="text/javascript">
  852. <!--
  853. var lastShownObj = '';
  854. var lastShownColor = '';
  855. function showHideMenu(objValue)
  856. {
  857. if (lastShownObj != '')
  858. {
  859. document.getElementById(lastShownObj+'_pointer').getElementsByTagName('a')[0].style.color = lastShownColor;
  860. document.getElementById(lastShownObj + '_on').style.display = 'none';
  861. }
  862. lastShownObj = objValue;
  863. lastShownColor = document.getElementById(objValue+'_pointer').getElementsByTagName('a')[0].style.color;
  864. document.getElementById(objValue + '_on').style.display = 'block';
  865. document.getElementById(objValue+'_pointer').getElementsByTagName('a')[0].style.color = '#000';
  866. }
  867. //-->
  868. </script>
  869. <?php
  870. $buffer = ob_get_contents();
  871. ob_end_clean();
  872. $DSP->body .= $buffer;
  873. // Third table cell contains are preferences in hidden <div>'s
  874. $r = $DSP->form_open(array('action' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=update_preferences'));
  875. $r .= $DSP->input_hidden('weblog_id', $weblog_id);
  876. $r .= $DSP->qdiv('default', '', 'menu_contents');
  877. $r .= '<div id="weblog_on" style="display: none; padding:0; margin: 0;">';
  878. $r .= $DSP->table('tableBorder', '0', '', '100%');
  879. $r .= $DSP->tr();
  880. $r .= "<td class='tableHeadingAlt' id='weblog2' colspan='2'>";
  881. $r .= NBS.$LANG->line('weblog_base_setup').$DSP->td_c();
  882. $r .= $DSP->tr_c();
  883. /** -------------------------
  884. /** General settings
  885. /** ------------------------*/
  886. // Weblog "full name" field
  887. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  888. $r .= $DSP->tr().
  889. $DSP->table_qcell($style, $DSP->required().NBS.$DSP->qspan('defaultBold', $LANG->line('full_weblog_name', 'blog_title')), '50%').
  890. $DSP->table_qcell($style, $DSP->input_text('blog_title', $blog_title, '20', '100', 'input', '260px'), '50%').
  891. $DSP->tr_c();
  892. // Weblog "short name" field
  893. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  894. $r .= $DSP->tr().
  895. $DSP->table_qcell($style, $DSP->required().NBS.$DSP->qspan('defaultBold', $LANG->line('short_weblog_name', 'blog_name')).$DSP->nbs(2).'-'.$DSP->nbs(2).$LANG->line('single_word_no_spaces'), '50%').
  896. $DSP->table_qcell($style, $DSP->input_text('blog_name', $blog_name, '20', '40', 'input', '260px'), '50%').
  897. $DSP->tr_c();
  898. // Weblog descriptions field
  899. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  900. $r .= $DSP->tr().
  901. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('blog_description', 'blog_descriptions')), '50%').
  902. $DSP->table_qcell($style, $DSP->input_text('blog_description', $blog_description, '50', '225', 'input', '100%'), '50%').
  903. $DSP->tr_c();
  904. // Weblog Language
  905. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  906. $r .= $DSP->tr().
  907. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('blog_lang', 'blog_lang')), '50%').
  908. $DSP->table_qcell($style, $FNS->encoding_menu('languages', 'blog_lang', $blog_lang), '50%').
  909. $DSP->tr_c();
  910. // Weblog Encoding
  911. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  912. $r .= $DSP->tr().
  913. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('blog_encoding', 'blog_encoding')), '50%').
  914. $DSP->table_qcell($style, $FNS->encoding_menu('charsets', 'blog_encoding', $blog_encoding), '50%').
  915. $DSP->tr_c().
  916. $DSP->table_c();
  917. $r .= $DSP->div_c();
  918. /** ---------------------------
  919. /** Paths
  920. /** ---------------------------*/
  921. $r .= '<div id="paths_on" style="display: none; padding:0; margin: 0;">';
  922. $r .= $DSP->table('tableBorder', '0', '', '100%');
  923. $r .= $DSP->tr();
  924. $r .= "<td class='tableHeadingAlt' id='paths2' colspan='2'>";
  925. $r .= NBS.$LANG->line('paths').$DSP->td_c();
  926. $r .= $DSP->tr_c();
  927. // Weblog URL field
  928. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  929. $r .= $DSP->tr().
  930. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('blog_url', 'blog_url')).$DSP->qdiv('default', $LANG->line('weblog_url_exp')), '50%').
  931. $DSP->table_qcell($style, $DSP->input_text('blog_url', $blog_url, '50', '80', 'input', '100%'), '50%').
  932. $DSP->tr_c();
  933. // comment URL
  934. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  935. $r .= $DSP->tr().
  936. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('comment_url', 'comment_url')).$DSP->qdiv('default', $LANG->line('comment_url_exp')), '50%').
  937. $DSP->table_qcell($style, $DSP->input_text('comment_url', $comment_url, '50', '80', 'input', '100%'), '50%').
  938. $DSP->tr_c();
  939. // Search results URL
  940. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  941. $r .= $DSP->tr().
  942. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('search_results_url', 'search_results_url')).$DSP->qdiv('default', $LANG->line('search_results_url_exp')), '50%').
  943. $DSP->table_qcell($style, $DSP->input_text('search_results_url', $search_results_url, '50', '80', 'input', '100%'), '50%').
  944. $DSP->tr_c();
  945. // TB return URL
  946. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  947. $r .= $DSP->tr().
  948. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('tb_return_url', 'tb_return_url')).$DSP->qdiv('default', $LANG->line('tb_return_url_exp')), '50%').
  949. $DSP->table_qcell($style, $DSP->input_text('tb_return_url', $tb_return_url, '50', '80', 'input', '100%'), '50%').
  950. $DSP->tr_c();
  951. // Ping pMachine URL
  952. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  953. $r .= $DSP->tr().
  954. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('ping_return_url', 'ping_return_url')).$DSP->qdiv('default', $LANG->line('ping_return_url_exp')), '50%').
  955. $DSP->table_qcell($style, $DSP->input_text('ping_return_url', $ping_return_url, '50', '80', 'input', '100%'), '50%').
  956. $DSP->tr_c();
  957. // RSS URL - Extended Ping
  958. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  959. $r .= $DSP->tr().
  960. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('rss_url', 'rss_url')).$DSP->qdiv('default', $LANG->line('rss_url_exp')), '50%').
  961. $DSP->table_qcell($style, $DSP->input_text('rss_url', $rss_url, '50', '80', 'input', '100%'), '50%').
  962. $DSP->tr_c();
  963. // live_look_template
  964. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  965. $r .= $DSP->tr()
  966. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('live_look_template')))
  967. .$DSP->td($style, '50%')
  968. .$DSP->input_select_header('live_look_template')
  969. .$DSP->input_select_option('0', $LANG->line('no_live_look_template'), ($live_look_template == 0) ? '1' : 0);
  970. $sql = "SELECT tg.group_name, t.template_id, t.template_name
  971. FROM exp_template_groups tg, exp_templates t
  972. WHERE tg.group_id = t.group_id
  973. AND tg.site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' ";
  974. if (USER_BLOG == TRUE)
  975. {
  976. $sql .= "AND tg.group_id = '".$SESS->userdata['tmpl_group_id']."' ";
  977. }
  978. else
  979. {
  980. $sql .= "AND tg.is_user_blog = 'n' ";
  981. }
  982. $sql .= " ORDER BY tg.group_name, t.template_name";
  983. $tquery = $DB->query($sql);
  984. if ($tquery->num_rows > 0)
  985. {
  986. foreach ($tquery->result as $template)
  987. {
  988. $r .= $DSP->input_select_option($template['template_id'], $template['group_name'].'/'.$template['template_name'], (($template['template_id'] == $live_look_template) ? 1 : ''));
  989. }
  990. }
  991. $r .= $DSP->input_select_footer()
  992. .$DSP->td_c()
  993. .$DSP->tr_c();
  994. $r .= $DSP->tr_c().
  995. $DSP->table_c();
  996. $r .= $DSP->div_c();
  997. /** ---------------------------
  998. /** Administrative settings
  999. /** ---------------------------*/
  1000. $r .= '<div id="admin_on" style="display: none; padding:0; margin: 0;">';
  1001. $r .= $DSP->table('tableBorder', '0', '', '100%');
  1002. $r .= $DSP->tr();
  1003. $r .= "<td class='tableHeadingAlt' id='admin2' colspan='2'>";
  1004. $r .= NBS.$LANG->line('default_settings').$DSP->td_c();
  1005. $r .= $DSP->tr_c();
  1006. // Default status menu
  1007. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1008. $r .= $DSP->tr().
  1009. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('default_status')), '50%');
  1010. $r .= $DSP->td($style, '50%').
  1011. $DSP->input_select_header('deft_status');
  1012. $query = $DB->query("SELECT * FROM exp_statuses WHERE group_id = '".$DB->escape_str($status_group)."' ORDER BY status");
  1013. if ($query->num_rows == 0)
  1014. {
  1015. $selected = ($deft_status == 'open') ? 1 : '';
  1016. $r .= $DSP->input_select_option('open', $LANG->line('open'), $selected);
  1017. $selected = ($deft_status == 'closed') ? 1 : '';
  1018. $r .= $DSP->input_select_option('closed', $LANG->line('closed'), $selected);
  1019. }
  1020. else
  1021. {
  1022. foreach ($query->result as $row)
  1023. {
  1024. $selected = ($deft_status == $row['status']) ? 1 : '';
  1025. $status_name = ($row['status'] == 'open' OR $row['status'] == 'closed') ? $LANG->line($row['status']) : $row['status'];
  1026. $r .= $DSP->input_select_option($row['status'], $status_name, $selected);
  1027. }
  1028. }
  1029. $r .= $DSP->input_select_footer().
  1030. $DSP->td_c().
  1031. $DSP->tr_c();
  1032. // Default category menu
  1033. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1034. $r .= $DSP->tr().
  1035. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('default_category')), '50%');
  1036. $r .= $DSP->td($style, '50%').
  1037. $DSP->input_select_header('deft_category');
  1038. $selected = '';
  1039. $r .= $DSP->input_select_option('', $LANG->line('none'), $selected);
  1040. $cats = implode("','", $DB->escape_str(explode('|', $cat_group)));
  1041. $query = $DB->query("SELECT CONCAT(g.group_name, ': ', c.cat_name) as display_name, c.cat_id, c.cat_name, g.group_name
  1042. FROM exp_categories c, exp_category_groups g
  1043. WHERE g.group_id = c.group_id
  1044. AND c.group_id IN ('{$cats}') ORDER BY display_name");
  1045. if ($query->num_rows > 0)
  1046. {
  1047. foreach ($query->result as $row)
  1048. {
  1049. $selected = ($deft_category == $row['cat_id']) ? 1 : '';
  1050. $r .= $DSP->input_select_option($row['cat_id'], $row['display_name'], $selected);
  1051. }
  1052. }
  1053. $r .= $DSP->input_select_footer().
  1054. $DSP->td_c().
  1055. $DSP->tr_c();
  1056. // Enable comments
  1057. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1058. $r .= $DSP->tr()
  1059. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('deft_comments')), '50%')
  1060. .$DSP->td($style, '50%');
  1061. $r .= $LANG->line('yes')
  1062. .$DSP->input_radio('deft_comments', 'y', ($deft_comments == 'y') ? 1 : '').$DSP->nbs(3);
  1063. $r .= $LANG->line('no')
  1064. .$DSP->input_radio('deft_comments', 'n', ($deft_comments == 'n') ? 1 : '')
  1065. .$DSP->td_c()
  1066. .$DSP->tr_c();
  1067. // Enable trackback pings
  1068. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1069. $r .= $DSP->tr()
  1070. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('deft_trackbacks')), '50%')
  1071. .$DSP->td($style, '50%');
  1072. $selected = ($deft_trackbacks == 'y') ? 1 : '';
  1073. $r .= $LANG->line('yes')
  1074. .$DSP->input_radio('deft_trackbacks', 'y', $selected).$DSP->nbs(3);
  1075. $selected = ($deft_trackbacks == 'n') ? 1 : '';
  1076. $r .= $LANG->line('no')
  1077. .$DSP->input_radio('deft_trackbacks', 'n', $selected)
  1078. .$DSP->td_c()
  1079. .$DSP->tr_c();
  1080. // Default field for search excerpt
  1081. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1082. $r .= $DSP->tr()
  1083. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('search_excerpt')), '50%');
  1084. $r .= $DSP->td($style, '50%');
  1085. $query = $DB->query("SELECT field_id, field_label FROM exp_weblog_fields WHERE field_search = 'y' AND group_id = '".$DB->escape_str($field_group)."'");
  1086. $r .= $DSP->input_select_header('search_excerpt');
  1087. foreach ($query->result as $row)
  1088. {
  1089. $selected = ($search_excerpt == $row['field_id']) ? 1 : '';
  1090. $r .= $DSP->input_select_option($row['field_id'], $row['field_label'], $selected);
  1091. }
  1092. $r .= $DSP->input_select_footer();
  1093. $r .= $DSP->td_c().
  1094. $DSP->tr_c();
  1095. $r .= $DSP->table_c();
  1096. $r .= $DSP->div_c();
  1097. /** ---------------------------
  1098. /** Weblog posting settings
  1099. /** ---------------------------*/
  1100. $r .= '<div id="posting_on" style="display: none; padding:0; margin: 0;">';
  1101. $r .= $DSP->table('tableBorder', '0', '', '100%');
  1102. $r .= $DSP->tr();
  1103. $r .= "<td class='tableHeadingAlt' id='posting2' colspan='2'>";
  1104. $r .= NBS.$LANG->line('weblog_settings').$DSP->td_c();
  1105. $r .= $DSP->tr_c();
  1106. // HTML formatting
  1107. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1108. $r .= $DSP->tr().
  1109. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('weblog_html_formatting')), '50%');
  1110. $r .= $DSP->td($style, '50%').
  1111. $DSP->input_select_header('weblog_html_formatting');
  1112. $selected = ($weblog_html_formatting == 'none') ? 1 : '';
  1113. $r .= $DSP->input_select_option('none', $LANG->line('convert_to_entities'), $selected);
  1114. $selected = ($weblog_html_formatting == 'safe') ? 1 : '';
  1115. $r .= $DSP->input_select_option('safe', $LANG->line('allow_safe_html'), $selected);
  1116. $selected = ($weblog_html_formatting == 'all') ? 1 : '';
  1117. $r .= $DSP->input_select_option('all', $LANG->line('allow_all_html'), $selected);
  1118. $r .= $DSP->input_select_footer().
  1119. $DSP->td_c().
  1120. $DSP->tr_c();
  1121. // Allow IMG URLs?
  1122. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1123. $r .= $DSP->tr()
  1124. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('weblog_allow_img_urls')), '50%')
  1125. .$DSP->td($style, '50%');
  1126. $selected = ($weblog_allow_img_urls == 'y') ? 1 : '';
  1127. $r .= $LANG->line('yes')
  1128. .$DSP->input_radio('weblog_allow_img_urls', 'y', $selected).$DSP->nbs(3);
  1129. $selected = ($weblog_allow_img_urls == 'n') ? 1 : '';
  1130. $r .= $LANG->line('no')
  1131. .$DSP->input_radio('weblog_allow_img_urls', 'n', $selected)
  1132. .$DSP->td_c()
  1133. .$DSP->tr_c();
  1134. // Auto link URLs?
  1135. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1136. $r .= $DSP->tr()
  1137. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('auto_link_urls')), '50%')
  1138. .$DSP->td($style, '50%');
  1139. $selected = ($weblog_auto_link_urls == 'y') ? 1 : '';
  1140. $r .= $LANG->line('yes')
  1141. .$DSP->input_radio('weblog_auto_link_urls', 'y', $selected).$DSP->nbs(3);
  1142. $selected = ($weblog_auto_link_urls == 'n') ? 1 : '';
  1143. $r .= $LANG->line('no')
  1144. .$DSP->input_radio('weblog_auto_link_urls', 'n', $selected)
  1145. .$DSP->td_c()
  1146. .$DSP->tr_c();
  1147. $r .= $DSP->table_c();
  1148. $r .= $DSP->div_c();
  1149. /** ---------------------------
  1150. /** Versioning settings
  1151. /** ---------------------------*/
  1152. $r .= '<div id="versioning_on" style="display: none; padding:0; margin: 0;">';
  1153. $r .= $DSP->table('tableBorder', '0', '', '100%');
  1154. $r .= $DSP->tr();
  1155. $r .= "<td class='tableHeadingAlt' id='versioning2' colspan='2'>";
  1156. $r .= NBS.$LANG->line('versioning').$DSP->td_c();
  1157. $r .= $DSP->tr_c();
  1158. // Enable Versioning?
  1159. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1160. $r .= $DSP->tr()
  1161. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('enable_versioning')), '50%')
  1162. .$DSP->td($style, '50%');
  1163. $selected = ($enable_versioning == 'y') ? 1 : '';
  1164. $r .= $LANG->line('yes')
  1165. .$DSP->input_radio('enable_versioning', 'y', $selected).$DSP->nbs(3);
  1166. $selected = ($enable_versioning == 'n') ? 1 : '';
  1167. $r .= $LANG->line('no')
  1168. .$DSP->input_radio('enable_versioning', 'n', $selected)
  1169. .$DSP->td_c()
  1170. .$DSP->tr_c();
  1171. // Enable Quicksave versioning
  1172. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1173. $r .= $DSP->tr()
  1174. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('enable_qucksave_versioning')).BR.$LANG->line('quicksave_note'), '50%')
  1175. .$DSP->td($style, '50%');
  1176. $selected = ($enable_qucksave_versioning == 'y') ? 1 : '';
  1177. $r .= $LANG->line('yes')
  1178. .$DSP->input_radio('enable_qucksave_versioning', 'y', $selected).$DSP->nbs(3);
  1179. $selected = ($enable_qucksave_versioning == 'n') ? 1 : '';
  1180. $r .= $LANG->line('no')
  1181. .$DSP->input_radio('enable_qucksave_versioning', 'n', $selected)
  1182. .$DSP->td_c()
  1183. .$DSP->tr_c();
  1184. // Max Revisions
  1185. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1186. $x = $DSP->qdiv('itemWrapper', $DSP->input_checkbox('clear_versioning_data', 'y', 0).' '.$DSP->qspan('highlight', $LANG->line('clear_versioning_data')));
  1187. $r .= $DSP->tr().
  1188. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('max_revisions')).BR.$LANG->line('max_revisions_note'), '50%').
  1189. $DSP->table_qcell($style, $DSP->input_text('max_revisions', $max_revisions, '30', '4', 'input', '100%').$x, '50%').
  1190. $DSP->tr_c();
  1191. $r .= $DSP->table_c();
  1192. $r .= $DSP->div_c();
  1193. /** ---------------------------
  1194. /** Notifications
  1195. /** ---------------------------*/
  1196. $r .= '<div id="not_on" style="display: none; padding:0; margin: 0;">';
  1197. $r .= $DSP->table('tableBorder', '0', '', '100%');
  1198. $r .= $DSP->tr();
  1199. $r .= "<td class='tableHeadingAlt' id='not2' colspan='2'>";
  1200. $r .= NBS.$LANG->line('notification_settings').$DSP->td_c();
  1201. $r .= $DSP->tr_c();
  1202. // Weblog notify?
  1203. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1204. $r .= $DSP->tr()
  1205. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('weblog_notify')), '50%')
  1206. .$DSP->td($style, '50%');
  1207. $selected = ($weblog_notify == 'y') ? 1 : '';
  1208. $r .= $LANG->line('yes')
  1209. .$DSP->input_radio('weblog_notify', 'y', $selected).$DSP->nbs(3);
  1210. $selected = ($weblog_notify == 'n') ? 1 : '';
  1211. $r .= $LANG->line('no')
  1212. .$DSP->input_radio('weblog_notify', 'n', $selected)
  1213. .$DSP->td_c()
  1214. .$DSP->tr_c();
  1215. // Weblog emails
  1216. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1217. $r .= $DSP->tr().
  1218. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('comment_notify_emails')).BR.$LANG->line('comment_notify_note'), '50%').
  1219. $DSP->table_qcell($style, $DSP->input_text('weblog_notify_emails', $weblog_notify_emails, '50', '255', 'input', '100%'), '50%').
  1220. $DSP->tr_c();
  1221. // Comment notify?
  1222. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1223. $r .= $DSP->tr()
  1224. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('comment_notify')), '50%')
  1225. .$DSP->td($style, '50%');
  1226. $selected = ($comment_notify == 'y') ? 1 : '';
  1227. $r .= $LANG->line('yes')
  1228. .$DSP->input_radio('comment_notify', 'y', $selected).$DSP->nbs(3);
  1229. $selected = ($comment_notify == 'n') ? 1 : '';
  1230. $r .= $LANG->line('no')
  1231. .$DSP->input_radio('comment_notify', 'n', $selected)
  1232. .$DSP->td_c()
  1233. .$DSP->tr_c();
  1234. // Comment emails
  1235. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1236. $r .= $DSP->tr().
  1237. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('comment_notify_emails', 'comment_notify_emails')).BR.$LANG->line('comment_notify_note'), '50%').
  1238. $DSP->table_qcell($style, $DSP->input_text('comment_notify_emails', $comment_notify_emails, '50', '255', 'input', '100%'), '50%').
  1239. $DSP->tr_c();
  1240. // Comment notify authors?
  1241. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1242. $r .= $DSP->tr()
  1243. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('comment_notify_authors')), '50%')
  1244. .$DSP->td($style, '50%');
  1245. $selected = ($comment_notify_authors == 'y') ? 1 : '';
  1246. $r .= $LANG->line('yes')
  1247. .$DSP->input_radio('comment_notify_authors', 'y', $selected).$DSP->nbs(3);
  1248. $selected = ($comment_notify_authors == 'n') ? 1 : '';
  1249. $r .= $LANG->line('no')
  1250. .$DSP->input_radio('comment_notify_authors', 'n', $selected)
  1251. .$DSP->td_c()
  1252. .$DSP->tr_c();
  1253. $r .= $DSP->table_c();
  1254. $r .= $DSP->div_c();
  1255. /** ---------------------------
  1256. /** Comment posting settings
  1257. /** ---------------------------*/
  1258. $r .= '<div id="comm_on" style="display: none; padding:0; margin: 0;">';
  1259. $r .= $DSP->table('tableBorder', '0', '', '100%');
  1260. $r .= $DSP->tr();
  1261. $r .= "<td class='tableHeadingAlt' id='comm2' colspan='2'>";
  1262. $r .= NBS.$LANG->line('comment_prefs').$DSP->td_c();
  1263. $r .= $DSP->tr_c();
  1264. // Are comments enabled?
  1265. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1266. $r .= $DSP->tr()
  1267. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('comment_system_enabled')), '50%')
  1268. .$DSP->td($style, '50%');
  1269. $selected = ($comment_system_enabled == 'y') ? 1 : '';
  1270. $r .= $LANG->line('yes')
  1271. .$DSP->input_radio('comment_system_enabled', 'y', $selected).$DSP->nbs(3);
  1272. $selected = ($comment_system_enabled == 'n') ? 1 : '';
  1273. $r .= $LANG->line('no')
  1274. .$DSP->input_radio('comment_system_enabled', 'n', $selected)
  1275. .$DSP->td_c()
  1276. .$DSP->tr_c();
  1277. // Require membership for comment posting?
  1278. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1279. $r .= $DSP->tr()
  1280. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('comment_require_membership')), '50%')
  1281. .$DSP->td($style, '50%');
  1282. $selected = ($comment_require_membership == 'y') ? 1 : '';
  1283. $r .= $LANG->line('yes')
  1284. .$DSP->input_radio('comment_require_membership', 'y', $selected).$DSP->nbs(3);
  1285. $selected = ($comment_require_membership == 'n') ? 1 : '';
  1286. $r .= $LANG->line('no')
  1287. .$DSP->input_radio('comment_require_membership', 'n', $selected)
  1288. .$DSP->td_c()
  1289. .$DSP->tr_c();
  1290. // Use captcha
  1291. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1292. $r .= $DSP->tr()
  1293. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('comment_use_captcha')).$DSP->qdiv('default', $LANG->line('captcha_explanation')), '50%')
  1294. .$DSP->td($style, '50%');
  1295. $selected = ($comment_use_captcha == 'y') ? 1 : '';
  1296. $r .= $LANG->line('yes')
  1297. .$DSP->input_radio('comment_use_captcha', 'y', $selected).$DSP->nbs(3);
  1298. $selected = ($comment_use_captcha == 'n') ? 1 : '';
  1299. $r .= $LANG->line('no')
  1300. .$DSP->input_radio('comment_use_captcha', 'n', $selected)
  1301. .$DSP->td_c()
  1302. .$DSP->tr_c();
  1303. // Require email address for comment posting?
  1304. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1305. $r .= $DSP->tr()
  1306. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('comment_require_email')), '50%')
  1307. .$DSP->td($style, '50%');
  1308. $selected = ($comment_require_email == 'y') ? 1 : '';
  1309. $r .= $LANG->line('yes')
  1310. .$DSP->input_radio('comment_require_email', 'y', $selected).$DSP->nbs(3);
  1311. $selected = ($comment_require_email == 'n') ? 1 : '';
  1312. $r .= $LANG->line('no')
  1313. .$DSP->input_radio('comment_require_email', 'n', $selected)
  1314. .$DSP->td_c()
  1315. .$DSP->tr_c();
  1316. // Require comment moderation?
  1317. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1318. $r .= $DSP->tr()
  1319. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('comment_moderate')).$DSP->qdiv('itemWrapper', $LANG->line('comment_moderate_exp')), '50%')
  1320. .$DSP->td($style, '50%');
  1321. $selected = ($comment_moderate == 'y') ? 1 : '';
  1322. $r .= $LANG->line('yes')
  1323. .$DSP->input_radio('comment_moderate', 'y', $selected).$DSP->nbs(3);
  1324. $selected = ($comment_moderate == 'n') ? 1 : '';
  1325. $r .= $LANG->line('no')
  1326. .$DSP->input_radio('comment_moderate', 'n', $selected)
  1327. .$DSP->td_c()
  1328. .$DSP->tr_c();
  1329. // Max characters in comments
  1330. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1331. $r .= $DSP->tr().
  1332. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('comment_max_chars', 'comment_max_chars')), '50%').
  1333. $DSP->table_qcell($style, $DSP->input_text('comment_max_chars', $comment_max_chars, '10', '5', 'input', '50px'), '50%').
  1334. $DSP->tr_c();
  1335. // Comment Timelock
  1336. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1337. $r .= $DSP->tr().
  1338. $DSP->table_qcell($style, $DSP->qdiv('defaultBold', $LANG->line('comment_timelock', 'comment_timelock')).$DSP->qdiv('itemWrapper', $LANG->line('comment_timelock_desc')), '50%').
  1339. $DSP->table_qcell($style, $DSP->input_text('comment_timelock', $comment_timelock, '10', '5', 'input', '50px'), '50%').
  1340. $DSP->tr_c();
  1341. // Comment expiration
  1342. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1343. if ($comment_expiration == '')
  1344. $comment_expiration = 0;
  1345. $x = $DSP->qdiv('itemWrapper', $DSP->input_checkbox('apply_expiration_to_existing', 'y', 0).' '.$LANG->line('update_existing_comments'));
  1346. $r .= $DSP->tr().
  1347. $DSP->table_qcell($style, $DSP->qdiv('defaultBold', $LANG->line('comment_expiration', 'comment_expiration')).$DSP->qdiv('itemWrapper', $LANG->line('comment_expiration_desc')), '50%').
  1348. $DSP->table_qcell($style, $DSP->input_text('comment_expiration', $comment_expiration, '10', '5', 'input', '50px').$x, '50%').
  1349. $DSP->tr_c();
  1350. // Default comment text formatting
  1351. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1352. $r .= $DSP->tr().
  1353. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('comment_text_formatting')), '50%');
  1354. $r .= $DSP->td($style, '50%').
  1355. $DSP->input_select_header('comment_text_formatting');
  1356. $selected = ($comment_text_formatting == 'none') ? 1 : '';
  1357. $r .= $DSP->input_select_option('none', $LANG->line('none'), $selected);
  1358. $selected = ($comment_text_formatting == 'xhtml') ? 1 : '';
  1359. $r .= $DSP->input_select_option('xhtml', $LANG->line('xhtml'), $selected);
  1360. $selected = ($comment_text_formatting == 'br') ? 1 : '';
  1361. $r .= $DSP->input_select_option('br', $LANG->line('auto_br'), $selected);
  1362. $r .= $DSP->input_select_footer().
  1363. $DSP->td_c().
  1364. $DSP->tr_c();
  1365. // HTML formatting
  1366. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1367. $r .= $DSP->tr().
  1368. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('comment_html_formatting')), '50%');
  1369. $r .= $DSP->td($style, '50%').
  1370. $DSP->input_select_header('comment_html_formatting');
  1371. $selected = ($comment_html_formatting == 'none') ? 1 : '';
  1372. $r .= $DSP->input_select_option('none', $LANG->line('convert_to_entities'), $selected);
  1373. $selected = ($comment_html_formatting == 'safe') ? 1 : '';
  1374. $r .= $DSP->input_select_option('safe', $LANG->line('allow_safe_html'), $selected);
  1375. $selected = ($comment_html_formatting == 'all') ? 1 : '';
  1376. $r .= $DSP->input_select_option('all', $LANG->line('allow_all_html_not_recommended'), $selected);
  1377. $r .= $DSP->input_select_footer().
  1378. $DSP->td_c().
  1379. $DSP->tr_c();
  1380. // Allow IMG URLs?
  1381. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1382. $r .= $DSP->tr()
  1383. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('comment_allow_img_urls')), '50%')
  1384. .$DSP->td($style, '50%');
  1385. $selected = ($comment_allow_img_urls == 'y') ? 1 : '';
  1386. $r .= $LANG->line('yes')
  1387. .$DSP->input_radio('comment_allow_img_urls', 'y', $selected).$DSP->nbs(3);
  1388. $selected = ($comment_allow_img_urls == 'n') ? 1 : '';
  1389. $r .= $LANG->line('no')
  1390. .$DSP->input_radio('comment_allow_img_urls', 'n', $selected)
  1391. .$DSP->td_c()
  1392. .$DSP->tr_c();
  1393. // Auto link URLs?
  1394. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1395. $r .= $DSP->tr()
  1396. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('auto_link_urls')), '50%')
  1397. .$DSP->td($style, '50%');
  1398. $selected = ($comment_auto_link_urls == 'y') ? 1 : '';
  1399. $r .= $LANG->line('yes')
  1400. .$DSP->input_radio('comment_auto_link_urls', 'y', $selected).$DSP->nbs(3);
  1401. $selected = ($comment_auto_link_urls == 'n') ? 1 : '';
  1402. $r .= $LANG->line('no')
  1403. .$DSP->input_radio('comment_auto_link_urls', 'n', $selected)
  1404. .$DSP->td_c()
  1405. .$DSP->tr_c();
  1406. $r .= $DSP->table_c();
  1407. $r .= $DSP->div_c();
  1408. /** ---------------------------
  1409. /** Trackbacks
  1410. /** ---------------------------*/
  1411. $r .= '<div id="tb_on" style="display: none; padding:0; margin: 0;">';
  1412. $r .= $DSP->table('tableBorder', '0', '', '100%');
  1413. $r .= $DSP->tr();
  1414. $r .= "<td class='tableHeadingAlt' id='tb2' colspan='2'>";
  1415. $r .= NBS.$LANG->line('trackback_settings').$DSP->td_c();
  1416. $r .= $DSP->tr_c();
  1417. // Are trackbacks enabled?
  1418. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1419. $r .= $DSP->tr()
  1420. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('trackback_system_enabled')), '50%')
  1421. .$DSP->td($style, '50%');
  1422. $selected = ($trackback_system_enabled == 'y') ? 1 : '';
  1423. $r .= $LANG->line('yes')
  1424. .$DSP->input_radio('trackback_system_enabled', 'y', $selected).$DSP->nbs(3);
  1425. $selected = ($trackback_system_enabled == 'n') ? 1 : '';
  1426. $r .= $LANG->line('no')
  1427. .$DSP->input_radio('trackback_system_enabled', 'n', $selected)
  1428. .$DSP->td_c()
  1429. .$DSP->tr_c();
  1430. // Add trackback RDF to your pages
  1431. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1432. $r .= $DSP->tr()
  1433. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('enable_trackbacks')), '50%')
  1434. .$DSP->td($style, '50%');
  1435. $selected = ($enable_trackbacks == 'y') ? 1 : '';
  1436. $r .= $LANG->line('yes')
  1437. .$DSP->input_radio('enable_trackbacks', 'y', $selected).$DSP->nbs(3);
  1438. $selected = ($enable_trackbacks == 'n') ? 1 : '';
  1439. $r .= $LANG->line('no')
  1440. .$DSP->input_radio('enable_trackbacks', 'n', $selected)
  1441. .$DSP->td_c()
  1442. .$DSP->tr_c();
  1443. // Use Entry ID or URL Title?
  1444. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  1445. $r .= $DSP->tr()
  1446. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('trackback_use_url_title')).$DSP->qdiv('default', $LANG->line('trackback_use_url_title_exp')), '50%')
  1447. .$DSP->td($style, '50%');
  1448. $selected = ($trackback_use_url_title == 'y') ? 1 : '';
  1449. $r .= $LANG->line('yes')
  1450. .$DSP->input_radio('trackback_use_url_title', 'y', $selected).$DSP->nbs(3);
  1451. $selected = ($trackback_use_url_title == 'n') ? 1 : '';
  1452. $r .= $LANG->line('no')
  1453. .$DSP->input_radio('trackback_use_url_title', 'n', $selected)
  1454. .$DSP->td_c()
  1455. .$DSP->tr_c();
  1456. // Max trackback hits per hour
  1457. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1458. $r .= $DSP->tr().
  1459. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('trackback_max_hits', 'trackback_max_hits')), '50%').
  1460. $DSP->table_qcell($style, $DSP->input_text('trackback_max_hits', $trackback_max_hits, '15', '16', 'input', '80px'), '50%').
  1461. $DSP->tr_c();
  1462. // Use captcha
  1463. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1464. $r .= $DSP->tr()
  1465. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('trackback_use_captcha')).$DSP->qdiv('default', $LANG->line('trackback_captcha_exp')), '50%')
  1466. .$DSP->td($style, '50%');
  1467. $selected = ($trackback_use_captcha == 'y') ? 1 : '';
  1468. $r .= $LANG->line('yes')
  1469. .$DSP->input_radio('trackback_use_captcha', 'y', $selected).$DSP->nbs(3);
  1470. $selected = ($trackback_use_captcha == 'n') ? 1 : '';
  1471. $r .= $LANG->line('no')
  1472. .$DSP->input_radio('trackback_use_captcha', 'n', $selected)
  1473. .$DSP->td_c()
  1474. .$DSP->tr_c();
  1475. // Default field for trackback
  1476. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1477. $r .= $DSP->tr()
  1478. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('trackback_field')), '50%');
  1479. $r .= $DSP->td($style, '50%');
  1480. $query = $DB->query("SELECT field_id, field_label FROM exp_weblog_fields WHERE group_id = '".$DB->escape_str($field_group)."'");
  1481. if ($query->num_rows == 0)
  1482. {
  1483. $r .= '<b>'.$LANG->line('no_field_group_selected').'</b>';
  1484. }
  1485. else
  1486. {
  1487. $r .= $DSP->input_select_header('trackback_field');
  1488. foreach ($query->result as $row)
  1489. {
  1490. $selected = ($trackback_field == $row['field_id']) ? 1 : '';
  1491. $r .= $DSP->input_select_option($row['field_id'], $row['field_label'], $selected);
  1492. }
  1493. $r .= $DSP->input_select_footer();
  1494. }
  1495. $r .= $DSP->td_c()
  1496. .$DSP->tr_c();
  1497. $r .= $DSP->table_c();
  1498. $r .= $DSP->div_c();
  1499. /** ---------------------------
  1500. /** Publish Page customization
  1501. /** ---------------------------*/
  1502. $r .= '<div id="cust_on" style="display: none; padding:0; margin: 0;">';
  1503. $r .= $DSP->table('tableBorder', '0', '', '100%');
  1504. $r .= $DSP->tr();
  1505. $r .= "<td class='tableHeadingAlt' id='cust2' colspan='2'>";
  1506. $r .= NBS.$LANG->line('publish_page_customization').$DSP->td_c();
  1507. $r .= $DSP->tr_c();
  1508. // show_url_title
  1509. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1510. $r .= $DSP->tr()
  1511. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('show_url_title')), '50%')
  1512. .$DSP->td($style, '50%');
  1513. $r .= $LANG->line('yes')
  1514. .$DSP->input_radio('show_url_title', 'y', ($show_url_title == 'y') ? 1 : '').$DSP->nbs(3);
  1515. $r .= $LANG->line('no')
  1516. .$DSP->input_radio('show_url_title', 'n', ($show_url_title == 'n') ? 1 : '')
  1517. .$DSP->td_c()
  1518. .$DSP->tr_c();
  1519. // show_button_cluster
  1520. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1521. $r .= $DSP->tr()
  1522. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('show_button_cluster')), '50%')
  1523. .$DSP->td($style, '50%');
  1524. $r .= $LANG->line('yes')
  1525. .$DSP->input_radio('show_button_cluster', 'y', ($show_button_cluster == 'y') ? 1 : '').$DSP->nbs(3);
  1526. $r .= $LANG->line('no')
  1527. .$DSP->input_radio('show_button_cluster', 'n', ($show_button_cluster == 'n') ? 1 : '')
  1528. .$DSP->td_c()
  1529. .$DSP->tr_c();
  1530. // show_trackback_field
  1531. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1532. $r .= $DSP->tr()
  1533. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('show_trackback_field')), '50%')
  1534. .$DSP->td($style, '50%');
  1535. $r .= $LANG->line('yes')
  1536. .$DSP->input_radio('show_trackback_field', 'y', ($show_trackback_field == 'y') ? 1 : '').$DSP->nbs(3);
  1537. $r .= $LANG->line('no')
  1538. .$DSP->input_radio('show_trackback_field', 'n', ($show_trackback_field == 'n') ? 1 : '')
  1539. .$DSP->td_c()
  1540. .$DSP->tr_c();
  1541. // show_author_menu
  1542. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1543. $r .= $DSP->tr()
  1544. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('show_author_menu')), '50%')
  1545. .$DSP->td($style, '50%');
  1546. $r .= $LANG->line('yes')
  1547. .$DSP->input_radio('show_author_menu', 'y', ($show_author_menu == 'y') ? 1 : '').$DSP->nbs(3);
  1548. $r .= $LANG->line('no')
  1549. .$DSP->input_radio('show_author_menu', 'n', ($show_author_menu == 'n') ? 1 : '')
  1550. .$DSP->td_c()
  1551. .$DSP->tr_c();
  1552. // show_status_menu
  1553. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1554. $r .= $DSP->tr()
  1555. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('show_status_menu')), '50%')
  1556. .$DSP->td($style, '50%');
  1557. $r .= $LANG->line('yes')
  1558. .$DSP->input_radio('show_status_menu', 'y', ($show_status_menu == 'y') ? 1 : '').$DSP->nbs(3);
  1559. $r .= $LANG->line('no')
  1560. .$DSP->input_radio('show_status_menu', 'n', ($show_status_menu == 'n') ? 1 : '')
  1561. .$DSP->td_c()
  1562. .$DSP->tr_c();
  1563. // show_date_menu
  1564. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1565. $r .= $DSP->tr()
  1566. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('show_date_menu')), '50%')
  1567. .$DSP->td($style, '50%');
  1568. $r .= $LANG->line('yes')
  1569. .$DSP->input_radio('show_date_menu', 'y', ($show_date_menu == 'y') ? 1 : '').$DSP->nbs(3);
  1570. $r .= $LANG->line('no')
  1571. .$DSP->input_radio('show_date_menu', 'n', ($show_date_menu == 'n') ? 1 : '')
  1572. .$DSP->td_c()
  1573. .$DSP->tr_c();
  1574. // show_options_cluster
  1575. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1576. $r .= $DSP->tr()
  1577. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('show_options_cluster')), '50%')
  1578. .$DSP->td($style, '50%');
  1579. $r .= $LANG->line('yes')
  1580. .$DSP->input_radio('show_options_cluster', 'y', ($show_options_cluster == 'y') ? 1 : '').$DSP->nbs(3);
  1581. $r .= $LANG->line('no')
  1582. .$DSP->input_radio('show_options_cluster', 'n', ($show_options_cluster == 'n') ? 1 : '')
  1583. .$DSP->td_c()
  1584. .$DSP->tr_c();
  1585. // show_ping_cluster
  1586. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1587. $r .= $DSP->tr()
  1588. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('show_ping_cluster')), '50%')
  1589. .$DSP->td($style, '50%');
  1590. $r .= $LANG->line('yes')
  1591. .$DSP->input_radio('show_ping_cluster', 'y', ($show_ping_cluster == 'y') ? 1 : '').$DSP->nbs(3);
  1592. $r .= $LANG->line('no')
  1593. .$DSP->input_radio('show_ping_cluster', 'n', ($show_ping_cluster == 'n') ? 1 : '')
  1594. .$DSP->td_c()
  1595. .$DSP->tr_c();
  1596. // show_categories_menu
  1597. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1598. $r .= $DSP->tr()
  1599. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('show_categories_menu')), '50%')
  1600. .$DSP->td($style, '50%');
  1601. $r .= $LANG->line('yes')
  1602. .$DSP->input_radio('show_categories_menu', 'y', ($show_categories_menu == 'y') ? 1 : '').$DSP->nbs(3);
  1603. $r .= $LANG->line('no')
  1604. .$DSP->input_radio('show_categories_menu', 'n', ($show_categories_menu == 'n') ? 1 : '')
  1605. .$DSP->td_c()
  1606. .$DSP->tr_c();
  1607. // show_forum_cluster
  1608. if ($PREFS->ini('forum_is_installed') == "y")
  1609. {
  1610. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1611. $r .= $DSP->tr()
  1612. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('show_forum_cluster')), '50%')
  1613. .$DSP->td($style, '50%');
  1614. $r .= $LANG->line('yes')
  1615. .$DSP->input_radio('show_forum_cluster', 'y', ($show_forum_cluster == 'y') ? 1 : '').$DSP->nbs(3);
  1616. $r .= $LANG->line('no')
  1617. .$DSP->input_radio('show_forum_cluster', 'n', ($show_forum_cluster == 'n') ? 1 : '')
  1618. .$DSP->td_c()
  1619. .$DSP->tr_c();
  1620. }
  1621. // show_pages_cluster
  1622. if ($PREFS->ini('site_pages') !== FALSE)
  1623. {
  1624. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1625. $r .= $DSP->tr()
  1626. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('show_pages_cluster')), '50%')
  1627. .$DSP->td($style, '50%');
  1628. $r .= $LANG->line('yes')
  1629. .$DSP->input_radio('show_pages_cluster', 'y', ($show_pages_cluster == 'y') ? 1 : '').$DSP->nbs(3);
  1630. $r .= $LANG->line('no')
  1631. .$DSP->input_radio('show_pages_cluster', 'n', ($show_pages_cluster == 'n') ? 1 : '')
  1632. .$DSP->td_c()
  1633. .$DSP->tr_c();
  1634. }
  1635. // Show All Cluster
  1636. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1637. $r .= $DSP->tr()
  1638. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('show_show_all_cluster')), '50%')
  1639. .$DSP->td($style, '50%');
  1640. $r .= $LANG->line('yes')
  1641. .$DSP->input_radio('show_show_all_cluster', 'y', ($show_show_all_cluster == 'y') ? 1 : '').$DSP->nbs(3);
  1642. $r .= $LANG->line('no')
  1643. .$DSP->input_radio('show_show_all_cluster', 'n', ($show_show_all_cluster == 'n') ? 1 : '')
  1644. .$DSP->td_c()
  1645. .$DSP->tr_c();
  1646. // default_entry_title
  1647. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1648. $r .= $DSP->tr()
  1649. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('default_entry_title')), '50%')
  1650. .$DSP->td($style, '50%')
  1651. .$DSP->input_text('default_entry_title', $default_entry_title, '50', '255', 'input', '100%')
  1652. .$DSP->td_c()
  1653. .$DSP->tr_c();
  1654. // url_title_prefix
  1655. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo' ;
  1656. $r .= $DSP->tr()
  1657. .$DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('url_title_prefix')).$DSP->nbs(2).'-'.$DSP->nbs(2).$LANG->line('single_word_no_spaces'))
  1658. .$DSP->td($style, '50%')
  1659. .$DSP->input_text('url_title_prefix', $url_title_prefix, '50', '255', 'input', '100%')
  1660. .$DSP->td_c()
  1661. .$DSP->tr_c();
  1662. $r .= $DSP->table_c();
  1663. $r .= $DSP->div_c();
  1664. // BOTTOM SECTION OF PAGE
  1665. // Text: * Indicates required fields
  1666. $r .= $DSP->div('itemWrapper');
  1667. $r .= $DSP->qdiv('itemWrapper', $DSP->required(1));
  1668. // "Submit" button
  1669. $r .= $DSP->qdiv('itemWrapper', $DSP->input_submit($LANG->line('update')).NBS.$DSP->input_submit($LANG->line('update_and_return'),'return'));
  1670. $r.= $DSP->div_c().$DSP->form_close();
  1671. /** ----------------------------------
  1672. /** Create Our All Encompassing Table of Weblog Goodness
  1673. /** ----------------------------------*/
  1674. $DSP->body .= $DSP->table('', '0', '', '100%');
  1675. // List of our various preference areas begins here
  1676. $areas = array("weblog" => "weblog_base_setup",
  1677. "paths" => "paths",
  1678. "admin" => "default_settings",
  1679. "posting" => "weblog_settings",
  1680. "versioning" => "versioning",
  1681. "not" => "notification_settings",
  1682. "comm" => "comment_prefs",
  1683. "tb" => "trackback_settings",
  1684. "cust" => "publish_page_customization");
  1685. $menu = '';
  1686. foreach($areas as $area => $area_lang)
  1687. {
  1688. $menu .= $DSP->qdiv('navPad', ' <span id="'.$area.'_pointer">&#8226; '.$DSP->anchor("#", $LANG->line($area_lang), 'onclick="showHideMenu(\''.$area.'\');"').'</span>');
  1689. }
  1690. $first_text = $DSP->div('tableHeadingAlt')
  1691. . $blog_title
  1692. .$DSP->div_c()
  1693. .$DSP->div('profileMenuInner')
  1694. . $menu
  1695. .$DSP->div_c();
  1696. // Create the Table
  1697. $table_row = array( 'first' => array('valign' => "top", 'width' => "220px", 'text' => $first_text),
  1698. 'second' => array('class' => "default", 'width' => "8px"),
  1699. 'third' => array('valign' => "top", 'text' => $r));
  1700. $DSP->body .= $DSP->table_row($table_row).
  1701. $DSP->table_c();
  1702. $DSP->title = $LANG->line('edit_weblog_prefs');
  1703. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  1704. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=blog_list', $LANG->line('weblog_management'))).
  1705. $DSP->crumb_item($LANG->line('edit_weblog_prefs'));
  1706. }
  1707. /* END */
  1708. /** -----------------------------------------------------------
  1709. /** Weblog group preferences form
  1710. /** -----------------------------------------------------------*/
  1711. // This function displays the form used to edit the various
  1712. // preferences and group assignements for a given weblog
  1713. //-----------------------------------------------------------
  1714. function edit_group_form()
  1715. {
  1716. global $DSP, $IN, $DB, $REGX, $LANG, $PREFS;
  1717. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  1718. {
  1719. return $DSP->no_access_message();
  1720. }
  1721. // Set default values
  1722. $i = 0;
  1723. // If we don't have the $weblog_id variable, bail out.
  1724. if ( ! $weblog_id = $IN->GBL('weblog_id'))
  1725. {
  1726. return FALSE;
  1727. }
  1728. $query = $DB->query("SELECT * FROM exp_weblogs WHERE weblog_id = '".$DB->escape_str($weblog_id)."'");
  1729. foreach ($query->row as $key => $val)
  1730. {
  1731. $$key = $val;
  1732. }
  1733. // Build the output
  1734. $DSP->body .= $DSP->form_open(array('action' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=update_preferences'));
  1735. $DSP->body .= $DSP->input_hidden('weblog_id', $weblog_id);
  1736. $DSP->body .= $DSP->input_hidden('blog_name', $blog_name);
  1737. $DSP->body .= $DSP->input_hidden('blog_title', $blog_title);
  1738. $DSP->body .= $DSP->input_hidden('return', '1');
  1739. $DSP->body .= $DSP->table('tableBorder', '0', '', '100%');
  1740. $DSP->body .= $DSP->tr().
  1741. $DSP->td('tableHeading', '100%').$LANG->line('edit_group_prefs').$DSP->td_c().
  1742. $DSP->tr_c();
  1743. $DSP->body .= $DSP->tr().
  1744. $DSP->table_qcell('tableCellTwo', $DSP->qdiv('itemWrapper', $DSP->qspan('defaultBold', $blog_title)), '50%').
  1745. $DSP->tr_c().
  1746. $DSP->table_c();
  1747. $DSP->body .= $DSP->table('tableBorder', '0', '', '100%');
  1748. $DSP->body .= $DSP->tr();
  1749. $DSP->body .= $DSP->table_qcell('tableHeadingAlt', $LANG->line('preference'));
  1750. $DSP->body .= $DSP->table_qcell('tableHeadingAlt', $LANG->line('value'));
  1751. $DSP->body .= $DSP->tr_c();
  1752. // GROUP FIELDS
  1753. $g = '';
  1754. // Category group select list
  1755. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  1756. $query = $DB->query("SELECT group_id, group_name FROM exp_category_groups WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' ORDER BY group_name");
  1757. $g .= $DSP->tr().
  1758. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('category_group')), '40%', 'top');
  1759. $g .= $DSP->td($style).
  1760. $DSP->input_select_header('cat_group[]', ($query->num_rows > 0) ? 'y' : '');
  1761. $selected = (empty($cat_group)) ? 1 : '';
  1762. $g .= $DSP->input_select_option('', $LANG->line('none'), $selected);
  1763. if ($query->num_rows > 0)
  1764. {
  1765. $cat_group = explode('|', $cat_group);
  1766. foreach ($query->result as $row)
  1767. {
  1768. $selected = (in_array($row['group_id'], $cat_group)) ? 1 : '';
  1769. $g .= $DSP->input_select_option($row['group_id'], $row['group_name'], $selected);
  1770. }
  1771. }
  1772. $g .= $DSP->input_select_footer().
  1773. $DSP->td_c().
  1774. $DSP->tr_c();
  1775. // Status group select list
  1776. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  1777. $query = $DB->query("SELECT group_id, group_name FROM exp_status_groups WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' ORDER BY group_name");
  1778. $g .= $DSP->tr().
  1779. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('status_group')));
  1780. $g .= $DSP->td($style).
  1781. $DSP->input_select_header('status_group');
  1782. $selected = '';
  1783. $g .= $DSP->input_select_option('', $LANG->line('none'), $selected);
  1784. if ($query->num_rows > 0)
  1785. {
  1786. foreach ($query->result as $row)
  1787. {
  1788. $selected = ($status_group == $row['group_id']) ? 1 : '';
  1789. $g .= $DSP->input_select_option($row['group_id'], $row['group_name'], $selected);
  1790. }
  1791. }
  1792. $g .= $DSP->input_select_footer().
  1793. $DSP->td_c().
  1794. $DSP->tr_c();
  1795. // Field group select list
  1796. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  1797. $query = $DB->query("SELECT group_id, group_name FROM exp_field_groups WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' ORDER BY group_name");
  1798. $g .= $DSP->tr().
  1799. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('field_group')));
  1800. $g .= $DSP->td($style).
  1801. $DSP->input_select_header('field_group');
  1802. $selected = '';
  1803. $g .= $DSP->input_select_option('', $LANG->line('none'), $selected);
  1804. if ($query->num_rows > 0)
  1805. {
  1806. foreach ($query->result as $row)
  1807. {
  1808. $selected = ($field_group == $row['group_id']) ? 1 : '';
  1809. $g .= $DSP->input_select_option($row['group_id'], $row['group_name'], $selected);
  1810. }
  1811. }
  1812. $g .= $DSP->input_select_footer().
  1813. $DSP->td_c().
  1814. $DSP->tr_c();
  1815. $DSP->body .= $g;
  1816. // BOTTOM SECTION OF PAGE
  1817. // Table end
  1818. $DSP->body .= $DSP->table_c();
  1819. $DSP->body .= $DSP->qdiv('itemWrapper', $DSP->input_submit($LANG->line('update')));
  1820. $DSP->body .= $DSP->form_close();
  1821. $DSP->title = $LANG->line('edit_group_prefs');
  1822. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  1823. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=blog_list', $LANG->line('weblog_management'))).
  1824. $DSP->crumb_item($LANG->line('edit_group_prefs'));
  1825. }
  1826. /* END */
  1827. /** -----------------------------------------------------------
  1828. /** Delete weblog confirm
  1829. /** -----------------------------------------------------------*/
  1830. // Warning message shown when you try to delete a weblog
  1831. //-----------------------------------------------------------
  1832. function delete_weblog_conf()
  1833. {
  1834. global $DSP, $IN, $DB, $LANG;
  1835. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  1836. {
  1837. return $DSP->no_access_message();
  1838. }
  1839. if ( ! $weblog_id = $IN->GBL('weblog_id'))
  1840. {
  1841. return FALSE;
  1842. }
  1843. $query = $DB->query("SELECT blog_title FROM exp_weblogs WHERE weblog_id = '".$DB->escape_str($weblog_id)."'");
  1844. $DSP->title = $LANG->line('delete_weblog');
  1845. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  1846. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=blog_list', $LANG->line('weblog_administration'))).
  1847. $DSP->crumb_item($LANG->line('delete_weblog'));
  1848. $DSP->body = $DSP->delete_confirmation(
  1849. array(
  1850. 'url' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=delete'.AMP.'weblog_id='.$weblog_id,
  1851. 'heading' => 'delete_weblog',
  1852. 'message' => 'delete_weblog_confirmation',
  1853. 'item' => $query->row['blog_title'],
  1854. 'extra' => '',
  1855. 'hidden' => array('weblog_id' => $weblog_id)
  1856. )
  1857. );
  1858. }
  1859. /* END */
  1860. /** -----------------------------------------------------------
  1861. /** Delete weblog
  1862. /** -----------------------------------------------------------*/
  1863. // This function deletes a given weblog
  1864. //-----------------------------------------------------------
  1865. function delete_weblog()
  1866. {
  1867. global $DSP, $IN, $DB, $LOG, $LANG, $PREFS, $STAT;
  1868. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  1869. {
  1870. return $DSP->no_access_message();
  1871. }
  1872. if ( ! $weblog_id = $IN->GBL('weblog_id'))
  1873. {
  1874. return FALSE;
  1875. }
  1876. if ( ! is_numeric($weblog_id))
  1877. {
  1878. return FALSE;
  1879. }
  1880. $query = $DB->query("SELECT blog_title FROM exp_weblogs WHERE weblog_id = '".$DB->escape_str($weblog_id)."'");
  1881. if ($query->num_rows == 0)
  1882. {
  1883. return FALSE;
  1884. }
  1885. $blog_title = $query->row['blog_title'];
  1886. $LOG->log_action($LANG->line('weblog_deleted').NBS.NBS.$blog_title);
  1887. $query = $DB->query("SELECT entry_id, author_id FROM exp_weblog_titles WHERE weblog_id = '{$weblog_id}'");
  1888. $entries = array();
  1889. $authors = array();
  1890. if ($query->num_rows > 0)
  1891. {
  1892. foreach ($query->result as $row)
  1893. {
  1894. $entries[] = $row['entry_id'];
  1895. $authors[] = $row['author_id'];
  1896. }
  1897. }
  1898. $authors = array_unique($authors);
  1899. // gather related fields, we use this later if needed
  1900. $fquery = $DB->query("SELECT field_id FROM exp_weblog_fields WHERE field_type = 'rel'");
  1901. $DB->query("DELETE FROM exp_weblog_data WHERE weblog_id = '{$weblog_id}'");
  1902. $DB->query("DELETE FROM exp_weblog_titles WHERE weblog_id = '{$weblog_id}'");
  1903. $DB->query("DELETE FROM exp_weblogs WHERE weblog_id = '{$weblog_id}'");
  1904. $DB->query("DELETE FROM exp_comments WHERE weblog_id = '{$weblog_id}'");
  1905. $DB->query("DELETE FROM exp_trackbacks WHERE weblog_id = '{$weblog_id}'");
  1906. /** ----------------------------------------
  1907. /** Delete Pages Stored in Database For Entries
  1908. /** ----------------------------------------*/
  1909. if (sizeof($entries) > 0 && $PREFS->ini('site_pages') !== FALSE)
  1910. {
  1911. $pages = $PREFS->ini('site_pages');
  1912. if (sizeof($pages) > 0)
  1913. {
  1914. foreach($entries as $entry_id)
  1915. {
  1916. unset($pages['uris'][$entry_id]);
  1917. unset($pages['templates'][$entry_id]);
  1918. }
  1919. $PREFS->core_ini['site_pages'] = $pages;
  1920. $DB->query($DB->update_string('exp_sites',
  1921. array('site_pages' => addslashes(serialize($pages))),
  1922. "site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'"));
  1923. }
  1924. }
  1925. /** ---------------------------------------
  1926. /** Clear relationships and catagories
  1927. /** ---------------------------------------*/
  1928. if (! empty($entries))
  1929. {
  1930. $ENTRY_IDS = implode(',', $entries);
  1931. // Clear the exp_category_posts table
  1932. $DB->query("DELETE FROM exp_category_posts WHERE entry_id IN ({$ENTRY_IDS})");
  1933. // Now it's relationships turn
  1934. $DB->query("DELETE FROM exp_relationships WHERE rel_parent_id IN ({$ENTRY_IDS})");
  1935. $child_results = $DB->query("SELECT rel_id FROM exp_relationships WHERE rel_child_id IN ({$ENTRY_IDS})");
  1936. if ($child_results->num_rows > 0)
  1937. {
  1938. // We have children, so we need to do a bit of housekeeping
  1939. // so parent entries don't continue to try to reference them
  1940. $cids = array();
  1941. foreach ($child_results->result as $row)
  1942. {
  1943. $cids[] = $row['rel_id'];
  1944. }
  1945. $CIDS = implode(',', $cids);
  1946. foreach($fquery->result as $row)
  1947. {
  1948. $DB->query($DB->update_string('exp_weblog_data', array('field_id_'.$row['field_id'] => '0'), 'field_id_'.$row['field_id']." IN ({$CIDS})"));
  1949. }
  1950. }
  1951. $DB->query("DELETE FROM exp_relationships WHERE rel_child_id IN ({$ENTRY_IDS})");
  1952. }
  1953. /** ---------------------------------------
  1954. /** Update author stats
  1955. /** ---------------------------------------*/
  1956. foreach ($authors as $author_id)
  1957. {
  1958. $query = $DB->query("SELECT count(entry_id) AS count FROM exp_weblog_titles WHERE author_id = '{$author_id}'");
  1959. $total_entries = $query->row['count'];
  1960. $query = $DB->query("SELECT count(comment_id) AS count FROM exp_comments WHERE author_id = '{$author_id}'");
  1961. $total_comments = $query->row['count'];
  1962. $DB->query($DB->update_string('exp_members', array( 'total_entries' => $total_entries,'total_comments' => $total_comments), "member_id = '{$author_id}'"));
  1963. }
  1964. /** ---------------------------------------
  1965. /** McFly, update the stats!
  1966. /** ---------------------------------------*/
  1967. $STAT->update_weblog_stats();
  1968. $STAT->update_comment_stats('', '', TRUE);
  1969. $STAT->update_trackback_stats();
  1970. return $this->weblog_overview($DSP->qspan('success', $LANG->line('weblog_deleted').NBS.NBS.'<b>'.$blog_title.'</b>'));
  1971. }
  1972. /* END */
  1973. //=====================================================================
  1974. // CATEGORY ADMINISTRATION FUNCTIONS
  1975. //=====================================================================
  1976. /** -----------------------------------------------------------
  1977. /** Category overview page
  1978. /** -----------------------------------------------------------*/
  1979. // This function displays the "categories" page, accessed
  1980. // via the "admin" tab
  1981. //-----------------------------------------------------------
  1982. function category_overview($message = '')
  1983. {
  1984. global $LANG, $DSP, $SESS, $DB, $PREFS;
  1985. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  1986. {
  1987. return $DSP->no_access_message();
  1988. }
  1989. $DSP->title = $LANG->line('category_groups');
  1990. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  1991. $DSP->crumb_item($LANG->line('category_groups'));
  1992. $DSP->right_crumb($LANG->line('create_new_category_group'), BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=cat_group_editor');
  1993. // Fetch category groups
  1994. $sql = "SELECT group_id, group_name FROM exp_category_groups WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND exp_category_groups.is_user_blog = 'n' ORDER BY group_name";
  1995. $query = $DB->query($sql);
  1996. if ($query->num_rows == 0)
  1997. {
  1998. $DSP->body = $DSP->heading($LANG->line('categories'));
  1999. $DSP->body .= stripslashes($message);
  2000. $DSP->body .= $DSP->div('box');
  2001. $DSP->body .= $DSP->qdiv('itemWrapper', $DSP->heading($LANG->line('no_category_group_message'), 5));
  2002. $DSP->body .= $DSP->qdiv('itemWrapper', $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=cat_group_editor', $LANG->line('create_new_category_group')));
  2003. $DSP->body .= $DSP->div_c();
  2004. return;
  2005. }
  2006. // Fetch count of custom fields per group
  2007. $cfcount = array();
  2008. $cfq = $DB->query("SELECT COUNT(*) AS count, group_id FROM exp_category_fields GROUP BY group_id");
  2009. if ($cfq->num_rows > 0)
  2010. {
  2011. foreach ($cfq->result as $row)
  2012. {
  2013. $cfcount[$row['group_id']] = $row['count'];
  2014. }
  2015. }
  2016. $r = '';
  2017. if ($message != '')
  2018. $r .= stripslashes($message);
  2019. $r .= $DSP->table('tableBorder', '0', '', '100%').
  2020. $DSP->tr().
  2021. $DSP->td('tableHeading', '', '6').
  2022. $LANG->line('categories').
  2023. $DSP->td_c().
  2024. $DSP->tr_c();
  2025. $i = 0;
  2026. foreach($query->result as $row)
  2027. {
  2028. // It is not efficient to put this query in the loop.
  2029. // Originally I did it with a join above, but there is a bug on OS X Server
  2030. // that I couldn't find a work-around for. So... query in the loop it is.
  2031. $res = $DB->query("SELECT COUNT(*) AS count FROM exp_categories WHERE group_id = '".$row['group_id']."'");
  2032. $count = $res->row['count'];
  2033. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  2034. $r .= $DSP->tr().
  2035. $DSP->td($style, '5%').
  2036. $DSP->qspan('defaultBold', $row['group_id']).
  2037. $DSP->td_c().
  2038. $DSP->td($style, '30%').
  2039. $DSP->qspan('defaultBold', $row['group_name']).
  2040. $DSP->td_c();
  2041. $r .= $DSP->table_qcell($style,
  2042. '('.$count.')'.$DSP->nbs(2).
  2043. $DSP->anchor(
  2044. BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=category_editor'.AMP.'group_id='.$row['group_id'],
  2045. $LANG->line('add_edit_categories')
  2046. ));
  2047. $r .= $DSP->table_qcell($style,
  2048. $DSP->anchor(
  2049. BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=cat_group_editor'.AMP.'group_id='.$row['group_id'],
  2050. $LANG->line('edit_group_name')
  2051. ));
  2052. $r .= $DSP->table_qcell($style,
  2053. '('.((isset($cfcount[$row['group_id']])) ? $cfcount[$row['group_id']] : '0').')'.$DSP->nbs(2).
  2054. $DSP->anchor(
  2055. BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=cat_field_group_edit'.AMP.'group_id='.$row['group_id'],
  2056. $LANG->line('manage_custom_fields')
  2057. ));
  2058. $r .= $DSP->table_qcell($style,
  2059. $DSP->anchor(
  2060. BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=cat_group_del_conf'.AMP.'group_id='.$row['group_id'],
  2061. $LANG->line('delete_group')
  2062. )).
  2063. $DSP->tr_c();
  2064. }
  2065. $r .= $DSP->table_c();
  2066. $DSP->body = $r;
  2067. }
  2068. /* END */
  2069. /** -----------------------------------------------------------
  2070. /** Category Field Group Form
  2071. /** -----------------------------------------------------------*/
  2072. // This function displays the field group management form
  2073. // and allows you to delete, modify, or create a
  2074. // category custom field
  2075. //-----------------------------------------------------------
  2076. function category_field_group_manager($group_id = '', $msg = FALSE)
  2077. {
  2078. global $DSP, $IN, $DB, $LANG;
  2079. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  2080. {
  2081. return $DSP->no_access_message();
  2082. }
  2083. $message = ($msg == TRUE) ? $DSP->qdiv('success', $LANG->line('preferences_updated')) : '';
  2084. if ($group_id == '')
  2085. {
  2086. if (($group_id = $IN->GBL('group_id')) === FALSE OR ! is_numeric($group_id))
  2087. {
  2088. return FALSE;
  2089. }
  2090. }
  2091. elseif ( ! is_numeric($group_id))
  2092. {
  2093. return FALSE;
  2094. }
  2095. // Fetch the name of the category group
  2096. $query = $DB->query("SELECT group_name FROM exp_category_groups WHERE group_id = '".$DB->escape_str($group_id)."'");
  2097. $r = $DSP->qdiv('tableHeading', $LANG->line('category_group').':'.$DSP->nbs(2).$query->row['group_name']);
  2098. if ($message != '')
  2099. {
  2100. $r .= $DSP->qdiv('box', stripslashes($message));
  2101. }
  2102. $r .= $DSP->table('tableBorder', '0', '10', '100%').
  2103. $DSP->tr().
  2104. $DSP->td('tableHeadingAlt', '40%', '1').$LANG->line('field_label').$DSP->td_c().
  2105. $DSP->td('tableHeadingAlt', '20%', '1').$LANG->line('field_name').$DSP->td_c().
  2106. $DSP->td('tableHeadingAlt', '40%', '2').$LANG->line('field_type').$DSP->td_c().
  2107. $DSP->tr_c();
  2108. $query = $DB->query("SELECT field_id, field_name, field_label, field_type, field_order FROM exp_category_fields WHERE group_id = '".$DB->escape_str($group_id)."' ORDER BY field_order");
  2109. if ($query->num_rows == 0)
  2110. {
  2111. $r .= $DSP->tr().
  2112. $DSP->td('tableCellTwo', '', 3).
  2113. '<b>'.$LANG->line('no_field_groups').'</br>'.
  2114. $DSP->td_c().
  2115. $DSP->tr_c();
  2116. }
  2117. $i = 0;
  2118. if ($query->num_rows > 0)
  2119. {
  2120. foreach ($query->result as $row)
  2121. {
  2122. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  2123. $r .= $DSP->tr();
  2124. $r .= $DSP->table_qcell($style, $DSP->qdiv('defaultBold', $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=edit_cat_field'.AMP.'group_id='.$group_id.AMP.'field_id='.$row['field_id'], $row['field_order'].$DSP->nbs(2).$row['field_label'])));
  2125. $r .= $DSP->table_qcell($style, $row['field_name']);
  2126. switch ($row['field_type'])
  2127. {
  2128. case 'text' : $field_type = $LANG->line('text_input');
  2129. break;
  2130. case 'textarea' : $field_type = $LANG->line('textarea');
  2131. break;
  2132. case 'select' : $field_type = $LANG->line('select_list');
  2133. break;
  2134. }
  2135. $r .= $DSP->table_qcell($style, $field_type);
  2136. $r .= $DSP->table_qcell($style, $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=del_cat_field_conf'.AMP.'group_id='.$group_id.AMP.'field_id='.$row['field_id'], $LANG->line('delete')));
  2137. $r .= $DSP->tr_c();
  2138. }
  2139. }
  2140. $r .= $DSP->table_c();
  2141. if ($query->num_rows > 0)
  2142. {
  2143. $r .= $DSP->qdiv('paddedWrapper', $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=edit_cat_field_order'.AMP.'group_id='.$group_id, $LANG->line('edit_field_order')));
  2144. }
  2145. $DSP->title = $LANG->line('custom_category_fields');
  2146. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  2147. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=categories', $LANG->line('category_groups'))).
  2148. $DSP->crumb_item($LANG->line('custom_category_fields'));
  2149. $DSP->right_crumb($LANG->line('create_new_custom_field'), BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=edit_cat_field'.AMP.'group_id='.$group_id);
  2150. $DSP->body = $r;
  2151. }
  2152. /* END */
  2153. /** -----------------------------------------------------------
  2154. /** Edit Category Field Order Form
  2155. /** -----------------------------------------------------------*/
  2156. // This function displays the form to modify the field display
  2157. // order in the control panel
  2158. //-----------------------------------------------------------
  2159. function edit_category_field_order_form()
  2160. {
  2161. global $DSP, $IN, $DB, $LANG;
  2162. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  2163. {
  2164. return $DSP->no_access_message();
  2165. }
  2166. if (($group_id = $IN->GBL('group_id')) === FALSE OR ! is_numeric($group_id))
  2167. {
  2168. return FALSE;
  2169. }
  2170. $query = $DB->query("SELECT field_id, field_label, field_order FROM exp_category_fields WHERE group_id = '".$DB->escape_str($group_id)."' ORDER BY field_order");
  2171. if ($query->num_rows == 0)
  2172. {
  2173. return FALSE;
  2174. }
  2175. $r = $DSP->form_open(array('action' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=ud_cat_field_order'));
  2176. $r .= $DSP->input_hidden('group_id', $group_id);
  2177. $r .= $DSP->table('tableBorder', '0', '10', '100%');
  2178. $r .= $DSP->tr()
  2179. .$DSP->td('tableHeading', '', '2').$LANG->line('edit_field_order').$DSP->td_c()
  2180. .$DSP->tr_c();
  2181. foreach ($query->result as $row)
  2182. {
  2183. $r .= $DSP->tr();
  2184. $r .= $DSP->table_qcell('tableCellOne', $row['field_label'], '40%');
  2185. $r .= $DSP->table_qcell('tableCellOne', $DSP->input_text('field_id_'.$row['field_id'], $row['field_order'], '4', '3', 'input', '30px'));
  2186. $r .= $DSP->tr_c();
  2187. }
  2188. $r .= $DSP->table_c();
  2189. $r .= $DSP->qdiv('itemWrapperTop', $DSP->input_submit($LANG->line('update')));
  2190. $r .= $DSP->form_close();
  2191. $DSP->title = $LANG->line('edit_field_order');
  2192. $DSP->crumb =
  2193. $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  2194. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=categories', $LANG->line('category_groups'))).
  2195. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=cat_field_group_edit'.AMP.'group_id='.$group_id, $LANG->line('custom_category_fields'))).
  2196. $DSP->crumb_item($LANG->line('edit_field_order'));
  2197. $DSP->body = $r;
  2198. }
  2199. /* END */
  2200. /** -----------------------------------------------------------
  2201. /** Update category field order
  2202. /** -----------------------------------------------------------*/
  2203. // This function updates the field order for category custom fields
  2204. //-----------------------------------------------------------
  2205. function update_category_field_order()
  2206. {
  2207. global $DSP, $IN, $DB, $LANG, $PREFS;
  2208. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  2209. {
  2210. return $DSP->no_access_message();
  2211. }
  2212. if (($group_id = $IN->GBL('group_id')) === FALSE OR ! is_numeric($group_id))
  2213. {
  2214. return FALSE;
  2215. }
  2216. unset($_POST['group_id']);
  2217. foreach ($_POST as $key => $val)
  2218. {
  2219. // remove 'field_id_' from key
  2220. $field_id = substr($key, 9);
  2221. $DB->query("UPDATE exp_category_fields SET field_order = '".$DB->escape_str($val)."'
  2222. WHERE group_id = '".$DB->escape_str($group_id)."' AND field_id = '".$DB->escape_str($field_id)."'");
  2223. }
  2224. return $this->category_field_group_manager($group_id);
  2225. }
  2226. /* END */
  2227. /** -----------------------------------------------------------
  2228. /** Edit Category Custom Field
  2229. /** -----------------------------------------------------------*/
  2230. // This function displays the form to edit or create
  2231. // a category custom field
  2232. //-----------------------------------------------------------
  2233. function edit_category_field_form()
  2234. {
  2235. global $DSP, $IN, $DB, $REGX, $LANG, $EXT, $PREFS;
  2236. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  2237. {
  2238. return $DSP->no_access_message();
  2239. }
  2240. if (($group_id = $IN->GBL('group_id')) === FALSE OR ! is_numeric($group_id))
  2241. {
  2242. return $DSP->no_access_message();
  2243. }
  2244. $type = ($field_id = $IN->GBL('field_id')) ? 'edit' : 'new';
  2245. $total_fields = '';
  2246. /** ---------------------------------------
  2247. /** Validate the group_id and field_id
  2248. /** ---------------------------------------*/
  2249. if ($type == 'new')
  2250. {
  2251. $query = $DB->query("SELECT group_id FROM exp_category_fields WHERE group_id = '".$DB->escape_str($group_id)."'");
  2252. $total_fields = $query->num_rows + 1;
  2253. $field_id = '';
  2254. if ($query->num_rows > 0)
  2255. {
  2256. $group_id = $query->row['group_id'];
  2257. }
  2258. else
  2259. {
  2260. // if there are no existing category fields yet for this group, this allows us to still validate the group_id
  2261. $gquery = $DB->query("SELECT COUNT(*) AS count FROM exp_category_groups WHERE group_id = '".$DB->escape_str($group_id)."' AND site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'");
  2262. if ($gquery->row['count'] != 1)
  2263. {
  2264. return $DSP->no_access_message();
  2265. }
  2266. }
  2267. }
  2268. else
  2269. {
  2270. $query = $DB->query("SELECT field_id, group_id FROM exp_category_fields WHERE group_id = '".$DB->escape_str($group_id)."' AND field_id = '".$DB->escape_str($field_id)."'");
  2271. if ($query->num_rows == 0)
  2272. {
  2273. return FALSE;
  2274. }
  2275. $field_id = $query->row['field_id'];
  2276. $group_id = $query->row['group_id'];
  2277. }
  2278. $DB->fetch_fields = TRUE;
  2279. $query = $DB->query("SELECT f.field_id, f.field_name, f.site_id, f.field_label, f.field_type, f.field_default_fmt, f.field_show_fmt,
  2280. f.field_list_items, f.field_maxl, f.field_ta_rows, f.field_text_direction, f.field_required, f.field_order,
  2281. g.group_name
  2282. FROM exp_category_fields AS f, exp_category_groups AS g
  2283. WHERE f.group_id = g.group_id
  2284. AND g.group_id = '{$group_id}'
  2285. AND f.field_id = '{$field_id}'");
  2286. $data = array();
  2287. if ($query->num_rows == 0)
  2288. {
  2289. foreach ($query->fields as $f)
  2290. {
  2291. $data[$f] = '';
  2292. $$f = '';
  2293. }
  2294. }
  2295. else
  2296. {
  2297. foreach ($query->row as $key => $val)
  2298. {
  2299. $data[$key] = $val;
  2300. $$key = $val;
  2301. }
  2302. }
  2303. // Adjust $group_name for new custom fields
  2304. // as we display this later
  2305. if ($group_name == '')
  2306. {
  2307. $query = $DB->query("SELECT group_name FROM exp_category_groups WHERE group_id = '{$group_id}'");
  2308. if ($query->num_rows > 0)
  2309. {
  2310. $group_name = $query->row['group_name'];
  2311. }
  2312. }
  2313. // JavaScript Stuff
  2314. $val = $LANG->line('field_val');
  2315. $r = "";
  2316. ob_start();
  2317. ?>
  2318. <script type="text/javascript">
  2319. <!--
  2320. function showhide_element(id)
  2321. {
  2322. if (id == 'text')
  2323. {
  2324. document.getElementById('text_block').style.display = "block";
  2325. document.getElementById('textarea_block').style.display = "none";
  2326. document.getElementById('select_block').style.display = "none";
  2327. }
  2328. else if (id == 'textarea')
  2329. {
  2330. document.getElementById('text_block').style.display = "none";
  2331. document.getElementById('textarea_block').style.display = "block";
  2332. document.getElementById('select_block').style.display = "none";
  2333. }
  2334. else if (id == 'select')
  2335. {
  2336. document.getElementById('text_block').style.display = "none";
  2337. document.getElementById('textarea_block').style.display = "none";
  2338. document.getElementById('select_block').style.display = "block";
  2339. }
  2340. }
  2341. function format_update_block(oldfmt, newfmt)
  2342. {
  2343. if (oldfmt == newfmt)
  2344. {
  2345. document.getElementById('update_formatting').style.display = "none";
  2346. document.field_form.update_formatting.checked=false;
  2347. }
  2348. else
  2349. {
  2350. document.getElementById('update_formatting').style.display = "block";
  2351. }
  2352. }
  2353. -->
  2354. </script>
  2355. <?php
  2356. $js = ob_get_contents();
  2357. ob_end_clean();
  2358. /* -------------------------------------------
  2359. /* 'publish_admin_edit_cat_field_js' hook.
  2360. /* - Allows modifying or adding onto Category Field JS
  2361. /* - Added 1.6.0
  2362. */
  2363. if ($EXT->active_hook('publish_admin_edit_cat_field_js') === TRUE)
  2364. {
  2365. $js = $EXT->call_extension('publish_admin_edit_cat_field_js', $data, $js);
  2366. }
  2367. /*
  2368. /* -------------------------------------------*/
  2369. $r .= $js;
  2370. $r .= NL.NL;
  2371. $typopts = '';
  2372. // Form declaration
  2373. $r .= $DSP->form_open(array('action' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=update_cat_fields', 'name' => 'field_form'));
  2374. $r .= $DSP->input_hidden('group_id', $group_id);
  2375. $r .= ($type == 'edit') ? $DSP->input_hidden('field_id', $field_id) : '';
  2376. $title = ($type == 'edit') ? 'edit_cat_field' : 'create_new_cat_field';
  2377. $r .= $DSP->table('tableBorder', '0', '10', '100%').
  2378. $DSP->tr().
  2379. $DSP->td('tableHeading', '', '2').$LANG->line($title).NBS.NBS."(".$LANG->line('category_group').": {$group_name})".$DSP->td_c().
  2380. $DSP->tr_c();
  2381. $i = 0;
  2382. /** ---------------------------------
  2383. /** Field name
  2384. /** ---------------------------------*/
  2385. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  2386. $r .= $DSP->tr();
  2387. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $DSP->required().NBS.$LANG->line('field_name', 'field_name')).$DSP->qdiv('itemWrapper', $LANG->line('field_name_cont')), '50%');
  2388. $r .= $DSP->table_qcell($style, $DSP->input_text('field_name', $field_name, '20', '60', 'input', '260px'), '50%');
  2389. $r .= $DSP->tr_c();
  2390. /** ---------------------------------
  2391. /** Field Label
  2392. /** ---------------------------------*/
  2393. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  2394. $r .= $DSP->tr();
  2395. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $DSP->required().NBS.$LANG->line('field_label', 'field_label')).$DSP->qdiv('', $LANG->line('cat_field_label_info')), '50%');
  2396. $r .= $DSP->table_qcell($style, $DSP->input_text('field_label', $field_label, '20', '60', 'input', '260px'), '50%');
  2397. $r .= $DSP->tr_c();
  2398. /** ---------------------------------
  2399. /** Field type
  2400. /** ---------------------------------*/
  2401. $sel_1 = ''; $sel_2 = ''; $sel_3 = '';
  2402. $text_js = ($type == 'edit') ? 'none' : 'block';
  2403. $textarea_js = 'none';
  2404. $select_js = 'none';
  2405. $select_opt_js = 'none';
  2406. switch ($field_type)
  2407. {
  2408. case 'text' : $sel_1 = 1; $text_js = 'block';
  2409. break;
  2410. case 'textarea' : $sel_2 = 1; $textarea_js = 'block';
  2411. break;
  2412. case 'select' : $sel_3 = 1; $select_js = 'block'; $select_opt_js = 'block';
  2413. break;
  2414. }
  2415. /** ---------------------------------
  2416. /** Create the pull-down menu
  2417. /** ---------------------------------*/
  2418. $typemenu = "<select name='field_type' class='select' onchange='showhide_element(this.options[this.selectedIndex].value);' >".NL;
  2419. $typemenu .= $DSP->input_select_option('text', $LANG->line('text_input'), $sel_1)
  2420. .$DSP->input_select_option('textarea', $LANG->line('textarea'), $sel_2)
  2421. .$DSP->input_select_option('select', $LANG->line('select_list'), $sel_3);
  2422. /* -------------------------------------------
  2423. /* 'publish_admin_edit_cat_field_type_pulldown' hook.
  2424. /* - Allows modifying or adding onto Category Field Type Menu Pulldown
  2425. /* - Added 1.6.0
  2426. */
  2427. if ($EXT->active_hook('publish_admin_edit_cat_field_type_pulldown') === TRUE)
  2428. {
  2429. $typemenu = $EXT->call_extension('publish_admin_edit_cat_field_type_pulldown', $data, $typemenu);
  2430. }
  2431. /*
  2432. /* -------------------------------------------*/
  2433. $typemenu .= $DSP->input_select_footer();
  2434. /* -------------------------------------------
  2435. /* 'publish_admin_edit_cat_field_type_cellone' hook.
  2436. /* - Allows modifying or adding onto Category Field Type - First Table Cell
  2437. /* - Added 1.6.0
  2438. */
  2439. if ($EXT->active_hook('publish_admin_edit_cat_field_type_cellone') === TRUE)
  2440. {
  2441. $typemenu = $EXT->call_extension('publish_admin_edit_cat_field_type_cellone', $data, $typemenu);
  2442. }
  2443. /*
  2444. /* -------------------------------------------*/
  2445. /** ---------------------------------
  2446. /** Select List Field
  2447. /** ---------------------------------*/
  2448. $typopts .= '<div id="select_block" style="display: '.$select_js.'; padding:0; margin:5px 0 0 0;">';
  2449. $typopts .= '<div id="populate_block_man" style="padding:0; margin:5px 0 0 0;">';
  2450. $typopts .= $DSP->qdiv('defaultBold', $LANG->line('field_list_items', 'field_list_items')).$DSP->qdiv('default', $LANG->line('field_list_instructions')).$DSP->input_textarea('field_list_items', $field_list_items, 10, 'textarea', '400px');
  2451. $typopts .= $DSP->div_c();
  2452. $typopts .= $DSP->div_c();
  2453. /* -------------------------------------------
  2454. /* 'publish_admin_edit_cat_field_type_celltwo' hook.
  2455. /* - Allows modifying or adding onto Category Field Type - Second Table Cell
  2456. /* - Added 1.6.0
  2457. */
  2458. if ($EXT->active_hook('publish_admin_edit_cat_field_type_celltwo') === TRUE)
  2459. {
  2460. $typopts = $EXT->call_extension('publish_admin_edit_cat_field_type_celltwo', $data, $typopts);
  2461. }
  2462. /*
  2463. /* -------------------------------------------*/
  2464. /** ---------------------------------
  2465. /** Max-length Field
  2466. /** ---------------------------------*/
  2467. if ($type != 'edit')
  2468. $field_maxl = 128;
  2469. $z = '<div id="text_block" style="display: '.$text_js.'; padding:0; margin:5px 0 0 0;">';
  2470. $z .= $DSP->qdiv('itemWrapper', NBS.NBS.$DSP->input_text('field_maxl', $field_maxl, '4', '3', 'input', '30px').NBS.$LANG->line('field_max_length', 'field_maxl'));
  2471. $z .= $DSP->div_c();
  2472. /** ---------------------------------
  2473. /** Textarea Row Field
  2474. /** ---------------------------------*/
  2475. if ($type != 'edit')
  2476. $field_ta_rows = 6;
  2477. $z .= '<div id="textarea_block" style="display: '.$textarea_js.'; padding:0; margin:5px 0 0 0;">';
  2478. $z .= $DSP->qdiv('itemWrapper', NBS.NBS.$DSP->input_text('field_ta_rows', $field_ta_rows, '4', '3', 'input', '30px').NBS.$LANG->line('textarea_rows', 'field_ta_rows'));
  2479. $z .= $DSP->div_c();
  2480. /** ---------------------------------
  2481. /** Generate the above items
  2482. /** ---------------------------------*/
  2483. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  2484. $r .= $DSP->tr();
  2485. $r .= $DSP->table_qcell($style, $DSP->qdiv('itemWrapper', $DSP->qspan('defaultBold', $LANG->line('field_type'))).$typemenu.$z, '50%', 'top');
  2486. $r .= $DSP->table_qcell($style, $typopts, '50%');
  2487. $r .= $DSP->tr_c();
  2488. /** ---------------------------------
  2489. /** Show field formatting?
  2490. /** ---------------------------------*/
  2491. if ($field_show_fmt == '')
  2492. $field_show_fmt = 'y';
  2493. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  2494. /** ---------------------------------
  2495. /** Field Formatting
  2496. /** ---------------------------------*/
  2497. if ($field_name != '')
  2498. $typemenu = "<select name='field_default_fmt' class='select' onchange='format_update_block(this.options[this.selectedIndex].value, \"".$field_default_fmt."\");' >".NL;
  2499. else
  2500. $typemenu = $DSP->input_select_header('field_default_fmt');
  2501. $typemenu .= $DSP->input_select_option('none', $LANG->line('none'), ($field_default_fmt == 'none') ? 1 : '');
  2502. // Fetch formatting plugins
  2503. $list = $this->fetch_plugins();
  2504. foreach($list as $val)
  2505. {
  2506. $name = ucwords(str_replace('_', ' ', $val));
  2507. if ($name == 'Br')
  2508. {
  2509. $name = $LANG->line('auto_br');
  2510. }
  2511. elseif ($name == 'Xhtml')
  2512. {
  2513. $name = $LANG->line('xhtml');
  2514. }
  2515. $selected = ($field_default_fmt == $val) ? 1 : '';
  2516. $typemenu .= $DSP->input_select_option($val, $name, $selected);
  2517. }
  2518. $typemenu .= $DSP->input_select_footer();
  2519. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  2520. $y = '<div id="formatting_block" style="padding:0; margin:0 0 0 0;">';
  2521. $y .= $typemenu;
  2522. $y .= $DSP->qdiv('itemWrapper', $DSP->input_radio('field_show_fmt', 'y', ($field_show_fmt == 'y') ? 1 : '').$LANG->line('show_formatting_buttons').BR.$DSP->input_radio('field_show_fmt', 'n', ($field_show_fmt == 'n') ? 1 : '').$LANG->line('hide_formatting_buttons'));
  2523. $y .= $DSP->div_c();
  2524. /* -------------------------------------------
  2525. /* 'publish_admin_edit_cat_field_format' hook.
  2526. /* - Allows modifying or adding onto Default Text Formatting Cell
  2527. /* - Added 1.6.0
  2528. */
  2529. if ($EXT->active_hook('publish_admin_edit_cat_field_format') === TRUE)
  2530. {
  2531. $y = $EXT->call_extension('publish_admin_edit_cat_field_format', $data, $y);
  2532. }
  2533. /*
  2534. /* -------------------------------------------*/
  2535. $r .= $DSP->tr();
  2536. $r .= $DSP->table_qcell($style, $DSP->qdiv('defaultBold', $LANG->line('deft_field_formatting')), '50%', 'top');
  2537. $r .= $DSP->table_qcell($style, $y, '50%');
  2538. $r .= $DSP->tr_c();
  2539. /** ---------------------------------
  2540. /** Text Direction
  2541. /** ---------------------------------*/
  2542. if ($field_text_direction == '') $field_text_direction = 'ltr';
  2543. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  2544. $r .= $DSP->tr();
  2545. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('text_direction')), '50%');
  2546. $r .= $DSP->table_qcell($style,
  2547. '<div id="direction_available" style="padding:0; margin:0 0 0 0;">'.
  2548. $LANG->line('ltr').$DSP->nbs().
  2549. $DSP->input_radio('field_text_direction', 'ltr', ($field_text_direction == 'ltr') ? 1 : '').
  2550. $DSP->nbs(3).
  2551. $LANG->line('rtl').$DSP->nbs().
  2552. $DSP->input_radio('field_text_direction', 'rtl', ($field_text_direction == 'rtl') ? 1 : '').
  2553. $DSP->div_c());
  2554. $r .= $DSP->tr_c();
  2555. /** ---------------------------------
  2556. /** Is field required?
  2557. /** ---------------------------------*/
  2558. if ($field_required == '') $field_required = 'n';
  2559. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  2560. $r .= $DSP->tr();
  2561. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('is_field_required')), '50%');
  2562. $r .= $DSP->table_qcell($style, $LANG->line('yes').$DSP->nbs().$DSP->input_radio('field_required', 'y', ($field_required == 'y') ? 1 : '').$DSP->nbs(3).$LANG->line('no').$DSP->nbs().$DSP->input_radio('field_required', 'n', ($field_required == 'n') ? 1 : ''), '50%');
  2563. $r .= $DSP->tr_c();
  2564. /** ---------------------------------
  2565. /** Field order
  2566. /** ---------------------------------*/
  2567. if ($type == 'new')
  2568. $field_order = $total_fields;
  2569. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  2570. $r .= $DSP->tr();
  2571. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('field_order', 'field_order')), '50%');
  2572. $r .= $DSP->table_qcell($style, $DSP->input_text('field_order', $field_order, '4', '3', 'input', '30px'), '50%');
  2573. $r .= $DSP->tr_c();
  2574. /* -------------------------------------------
  2575. /* 'publish_admin_edit_cat_field_extra_row' hook.
  2576. /* - Allows modifying or adding onto the Category Field settings table
  2577. /* - Added 1.6.0
  2578. */
  2579. if ($EXT->active_hook('publish_admin_edit_cat_field_extra_row') === TRUE)
  2580. {
  2581. $r = $EXT->call_extension('publish_admin_edit_cat_field_extra_row', $data, $r);
  2582. }
  2583. /*
  2584. /* -------------------------------------------*/
  2585. $r .= $DSP->table_c();
  2586. $r .= $DSP->div('itemWrapper');
  2587. $r .= $DSP->qdiv('itemWrapper', $DSP->required(1));
  2588. if ($field_name != '')
  2589. {
  2590. $r .= '<div id="update_formatting" style="display: none; padding:0; margin:0 0 0 0;">';
  2591. $r .= $DSP->div('itemWrapper');
  2592. $r .= $DSP->qdiv('alert', $LANG->line('fmt_has_changed'));
  2593. $r .= $DSP->qdiv('itemWrapper', $DSP->input_checkbox('update_formatting', 'y', 0).' '.$DSP->qspan('alert', $LANG->line('update_existing_cat_fields')));
  2594. $r .= $DSP->div_c();
  2595. $r .= $DSP->div_c();
  2596. }
  2597. if ($type == 'edit')
  2598. $r .= $DSP->input_submit($LANG->line('update'));
  2599. else
  2600. $r .= $DSP->input_submit($LANG->line('submit'));
  2601. $r .= $DSP->div_c();
  2602. $r .= $DSP->form_close();
  2603. $DSP->title = $LANG->line('custom_category_fields');
  2604. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  2605. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=categories', $LANG->line('category_groups'))).
  2606. $DSP->crumb_item($LANG->line('custom_category_fields'));
  2607. $DSP->body = $r;
  2608. }
  2609. /* END */
  2610. /** -----------------------------------------------------------
  2611. /** Update Category Fields
  2612. /** -----------------------------------------------------------*/
  2613. // This function updates or creates category fields
  2614. //-----------------------------------------------------------
  2615. function update_category_fields()
  2616. {
  2617. global $DSP, $FNS, $IN, $DB, $REGX, $LANG, $PREFS;
  2618. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  2619. {
  2620. return $DSP->no_access_message();
  2621. }
  2622. // Are we editing or creating?
  2623. $edit = (($field_id = $IN->GBL('field_id')) !== FALSE AND is_numeric($field_id)) ? TRUE : FALSE;
  2624. if (($group_id = $IN->GBL('group_id')) === FALSE OR ! is_numeric($group_id))
  2625. {
  2626. return $DSP->no_access_message();
  2627. }
  2628. // Check for required fields
  2629. $error = array();
  2630. if ($_POST['field_name'] == '')
  2631. {
  2632. $error[] = $LANG->line('no_field_name');
  2633. }
  2634. else
  2635. {
  2636. // Is the field one of the reserved words?
  2637. if (in_array($_POST['field_name'], $DSP->invalid_custom_field_names()))
  2638. {
  2639. $error[] = $LANG->line('reserved_word');
  2640. }
  2641. }
  2642. if ($_POST['field_label'] == '')
  2643. {
  2644. $error[] = $LANG->line('no_field_label');
  2645. }
  2646. // Does field name contain invalid characters?
  2647. if ( ! preg_match("#^[a-z0-9\_\-]+$#i", $_POST['field_name']))
  2648. {
  2649. $error[] = $LANG->line('invalid_characters');
  2650. }
  2651. // Field name must be unique across category groups
  2652. if ($edit == FALSE)
  2653. {
  2654. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_category_fields WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND field_name = '".$DB->escape_str($_POST['field_name'])."'");
  2655. if ($query->row['count'] > 0)
  2656. {
  2657. $error[] = $LANG->line('duplicate_field_name');
  2658. }
  2659. }
  2660. // Are there errors to display?
  2661. if (count($error) > 0)
  2662. {
  2663. $str = '';
  2664. foreach ($error as $msg)
  2665. {
  2666. $str .= $msg.BR;
  2667. }
  2668. return $DSP->error_message($str);
  2669. }
  2670. if ($_POST['field_list_items'] != '')
  2671. {
  2672. $_POST['field_list_items'] = $REGX->convert_quotes($_POST['field_list_items']);
  2673. }
  2674. if ( ! in_array($_POST['field_type'], array('text', 'textarea', 'select')))
  2675. {
  2676. $_POST['field_text_direction'] = 'ltr';
  2677. }
  2678. // Construct the query based on whether we are updating or inserting
  2679. if ($edit === TRUE)
  2680. {
  2681. // validate field id
  2682. $query = $DB->query("SELECT field_id FROM exp_category_fields WHERE group_id = '".$DB->escape_str($group_id)."' AND field_id = '".$DB->escape_str($field_id)."'");
  2683. if ($query->num_rows == 0)
  2684. {
  2685. return FALSE;
  2686. }
  2687. // Update the formatting for all existing entries
  2688. if (isset($_POST['update_formatting']))
  2689. {
  2690. $DB->query("UPDATE exp_category_field_data SET field_ft_{$field_id} = '".$DB->escape_str($_POST['field_default_fmt'])."'");
  2691. }
  2692. unset($_POST['group_id']);
  2693. unset($_POST['update_formatting']);
  2694. $DB->query($DB->update_string('exp_category_fields', $_POST, "field_id='".$field_id."'"));
  2695. }
  2696. else
  2697. {
  2698. unset($_POST['update_formatting']);
  2699. if ($_POST['field_order'] == 0 || $_POST['field_order'] == '')
  2700. {
  2701. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_category_fields WHERE group_id = '".$DB->escape_str($group_id)."'");
  2702. $_POST['field_order'] = $query->num_rows + 1;
  2703. }
  2704. $_POST['site_id'] = $PREFS->ini('site_id');
  2705. $DB->query($DB->insert_string('exp_category_fields', $_POST));
  2706. $insert_id = $DB->insert_id;
  2707. $DB->query("ALTER TABLE exp_category_field_data ADD COLUMN field_id_{$insert_id} text NOT NULL");
  2708. $DB->query("ALTER TABLE exp_category_field_data ADD COLUMN field_ft_{$insert_id} varchar(40) NOT NULL default 'none'");
  2709. $DB->query("UPDATE exp_category_field_data SET field_ft_{$insert_id} = '".$DB->escape_str($_POST['field_default_fmt'])."'");
  2710. }
  2711. $FNS->clear_caching('all', '', TRUE);
  2712. return $this->category_field_group_manager($group_id, $edit);
  2713. }
  2714. /* END */
  2715. /** -----------------------------------------------------------
  2716. /** Delete Category Custom Field Confirmation
  2717. /** -----------------------------------------------------------*/
  2718. // This function displays a confirmation form for deleting
  2719. // a category custom field
  2720. //-----------------------------------------------------------
  2721. function delete_category_field_confirm()
  2722. {
  2723. global $DSP, $IN, $DB, $LANG, $REGX;
  2724. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  2725. {
  2726. return $DSP->no_access_message();
  2727. }
  2728. if (($field_id = $IN->GBL('field_id')) === FALSE OR ! is_numeric($field_id))
  2729. {
  2730. return FALSE;
  2731. }
  2732. if (($group_id = $IN->GBL('group_id')) === FALSE OR ! is_numeric($group_id))
  2733. {
  2734. return FALSE;
  2735. }
  2736. $query = $DB->query("SELECT field_label FROM exp_category_fields
  2737. WHERE field_id = '".$DB->escape_str($field_id)."'
  2738. AND group_id = '".$DB->escape_str($group_id)."'");
  2739. if ($query->num_rows == 0)
  2740. {
  2741. return FALSE;
  2742. }
  2743. $DSP->title = $LANG->line('delete_field');
  2744. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  2745. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=categories', $LANG->line('category_groups'))).
  2746. $DSP->crumb_item($LANG->line('delete_cat_field'));
  2747. $DSP->body = $DSP->delete_confirmation(
  2748. array(
  2749. 'url' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=del_cat_field'.AMP.'group_id='.$group_id.AMP.'field_id='.$field_id,
  2750. 'heading' => 'delete_cat_field',
  2751. 'message' => 'delete_cat_field_confirmation',
  2752. 'item' => $query->row['field_label'],
  2753. 'extra' => '',
  2754. 'hidden' => array('field_id' => $field_id)
  2755. )
  2756. );
  2757. }
  2758. /* END */
  2759. /** -----------------------------------------------------------
  2760. /** Delete Category Field
  2761. /** -----------------------------------------------------------*/
  2762. // This function deletes a category field
  2763. //-----------------------------------------------------------
  2764. function delete_category_field()
  2765. {
  2766. global $DSP, $FNS, $IN, $DB, $LOG, $LANG;
  2767. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  2768. {
  2769. return $DSP->no_access_message();
  2770. }
  2771. if (($field_id = $IN->GBL('field_id', 'POST')) === FALSE OR ! is_numeric($field_id))
  2772. {
  2773. return FALSE;
  2774. }
  2775. if (($group_id = $IN->GBL('group_id')) === FALSE OR ! is_numeric($group_id))
  2776. {
  2777. return FALSE;
  2778. }
  2779. $query = $DB->query("SELECT field_id, field_name FROM exp_category_fields WHERE field_id = '".$DB->escape_str($field_id)."' AND group_id = '".$DB->escape_str($group_id)."'");
  2780. if ($query->num_rows == 0)
  2781. {
  2782. return $DSP->no_access_message();
  2783. }
  2784. $DB->query("DELETE FROM exp_category_fields WHERE field_id = {$field_id}");
  2785. $DB->query("ALTER TABLE exp_category_field_data DROP COLUMN field_id_{$field_id}");
  2786. $DB->query("ALTER TABLE exp_category_field_data DROP COLUMN field_ft_{$field_id}");
  2787. $LOG->log_action($LANG->line('cat_field_deleted').$DSP->nbs(2).$query->row['field_name']);
  2788. $FNS->clear_caching('all', '', TRUE);
  2789. return $this->category_field_group_manager($group_id);
  2790. }
  2791. /* END */
  2792. /** -----------------------------------------------------------
  2793. /** Category group form
  2794. /** -----------------------------------------------------------*/
  2795. // This function shows the form used to define a new category
  2796. // group or edit an existing one
  2797. //-----------------------------------------------------------
  2798. function edit_category_group_form()
  2799. {
  2800. global $DSP, $IN, $DB, $REGX, $LANG, $PREFS;
  2801. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  2802. {
  2803. return $DSP->no_access_message();
  2804. }
  2805. // Set default values
  2806. $edit = FALSE;
  2807. $group_id = '';
  2808. $group_name = '';
  2809. $field_html_formatting = 'all';
  2810. $can_edit = array();
  2811. $can_delete = array();
  2812. // If we have the group_id variable, it's an edit request, so fetch the category data
  2813. if ($group_id = $IN->GBL('group_id'))
  2814. {
  2815. $edit = TRUE;
  2816. if ( ! is_numeric($group_id))
  2817. {
  2818. return FALSE;
  2819. }
  2820. $query = $DB->query("SELECT * FROM exp_category_groups WHERE group_id = '".$DB->escape_str($group_id)."'");
  2821. foreach ($query->row as $key => $val)
  2822. {
  2823. $$key = $val;
  2824. }
  2825. // convert our | separated list of privileges into an array
  2826. $can_edit_categories = explode('|', rtrim($can_edit_categories, '|'));
  2827. $can_delete_categories = explode('|', rtrim($can_delete_categories, '|'));
  2828. }
  2829. else
  2830. {
  2831. $can_edit_categories = array();
  2832. $can_delete_categories = array();
  2833. }
  2834. /** ---------------------------------------
  2835. /** Grab member groups with potential privs
  2836. /** ---------------------------------------*/
  2837. $query = $DB->query("SELECT group_id, group_title, can_edit_categories, can_delete_categories
  2838. FROM exp_member_groups
  2839. WHERE group_id NOT IN (1,2,3,4)
  2840. AND site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'");
  2841. foreach ($query->result as $row)
  2842. {
  2843. if ($row['can_edit_categories'] == 'y')
  2844. {
  2845. $can_edit[$row['group_id']] = $row['group_title'];
  2846. }
  2847. if ($row['can_delete_categories'] == 'y')
  2848. {
  2849. $can_delete[$row['group_id']] = $row['group_title'];
  2850. }
  2851. }
  2852. $title = ($edit == FALSE) ? $LANG->line('create_new_category_group') : $LANG->line('edit_category_group');
  2853. // Build our output
  2854. $r = $DSP->form_open(array('action' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=update_cat_group'));
  2855. if ($edit == TRUE)
  2856. $r .= $DSP->input_hidden('group_id', $group_id);
  2857. $r .= $DSP->qdiv('tableHeading', $title);
  2858. $r .= $DSP->div('box').
  2859. $DSP->qdiv('itemWrapper', $DSP->qdiv('defaultBold', $LANG->line('name_of_category_group', 'group_name'))).
  2860. $DSP->qdiv('itemWrapper', $DSP->input_text('group_name', $group_name, '20', '50', 'input', '300px'));
  2861. $r .= BR.$DSP->qdiv('itemWrapper', $DSP->qdiv('defaultBold', $LANG->line('cat_field_html_formatting', 'field_html_formatting'))).
  2862. $DSP->div('itemWrapper').
  2863. $DSP->input_select_header('field_html_formatting');
  2864. $selected = ($field_html_formatting == 'none') ? 1 : '';
  2865. $r .= $DSP->input_select_option('none', $LANG->line('convert_to_entities'), $selected);
  2866. $selected = ($field_html_formatting == 'safe') ? 1 : '';
  2867. $r .= $DSP->input_select_option('safe', $LANG->line('allow_safe_html'), $selected);
  2868. $selected = ($field_html_formatting == 'all') ? 1 : '';
  2869. $r .= $DSP->input_select_option('all', $LANG->line('allow_all_html'), $selected);
  2870. $r .= $DSP->input_select_footer().
  2871. $DSP->div_c();
  2872. /** ---------------------------------------
  2873. /** Can Edit Categories drill down
  2874. /** ---------------------------------------*/
  2875. if (! empty($can_edit))
  2876. {
  2877. $r .= BR.$DSP->qdiv('itemWrapper', $DSP->qdiv('defaultBold', $LANG->line('can_edit_categories', 'can_edit_categories'))).
  2878. $DSP->div('itemWrapper').
  2879. $DSP->input_select_header('can_edit_categories[]', TRUE, (count($can_edit) > 8) ? 8 : count($can_edit) + 1, '30%;');
  2880. foreach ($can_edit as $group_id => $group_title)
  2881. {
  2882. $selected = (in_array($group_id, $can_edit_categories)) ? 1 : '';
  2883. $r .= $DSP->input_select_option($group_id, $group_title, $selected);
  2884. }
  2885. $r .= $DSP->input_select_footer().
  2886. $DSP->div_c();
  2887. }
  2888. else
  2889. {
  2890. $r .= BR.$DSP->qdiv('itemWrapper', $DSP->qdiv('defaultBold', $LANG->line('can_edit_categories'))).
  2891. $DSP->qdiv('itemWrapper', $DSP->qdiv('alert', str_replace('%x', strtolower($LANG->line('edit')), $LANG->line('no_member_groups_available'))).
  2892. BR.$DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=mbr_group_manager', $LANG->line('member_groups')));
  2893. }
  2894. /** ---------------------------------------
  2895. /** Can Delete Categories drill down
  2896. /** ---------------------------------------*/
  2897. if (! empty($can_delete))
  2898. {
  2899. $r .= BR.$DSP->qdiv('itemWrapper', $DSP->qdiv('defaultBold', $LANG->line('can_delete_categories', 'can_delete_categories'))).
  2900. $DSP->div('itemWrapper').
  2901. $DSP->input_select_header('can_delete_categories[]', TRUE, (count($can_delete) > 8) ? 8 : count($can_delete) + 1, '30%;');
  2902. foreach ($can_delete as $group_id => $group_title)
  2903. {
  2904. $selected = (in_array($group_id, $can_delete_categories)) ? 1 : '';
  2905. $r .= $DSP->input_select_option($group_id, $group_title, $selected);
  2906. }
  2907. $r .= $DSP->input_select_footer().
  2908. $DSP->div_c();
  2909. }
  2910. else
  2911. {
  2912. $r .= BR.$DSP->qdiv('itemWrapper', $DSP->qdiv('defaultBold', $LANG->line('can_delete_categories'))).
  2913. $DSP->qdiv('itemWrapper', $DSP->qdiv('alert', str_replace('%x', strtolower($LANG->line('delete')), $LANG->line('no_member_groups_available'))).
  2914. BR.$DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=members'.AMP.'P=mbr_group_manager', $LANG->line('member_groups')));
  2915. }
  2916. $r .= $DSP->div_c(); // main box
  2917. $r .= $DSP->div('itemWrapperTop');
  2918. if ($edit == FALSE)
  2919. $r .= $DSP->input_submit($LANG->line('submit'));
  2920. else
  2921. $r .= $DSP->input_submit($LANG->line('update'));
  2922. $r .= $DSP->div_c();
  2923. $r .= $DSP->form_close();
  2924. $DSP->title = $title;
  2925. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  2926. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=categories', $LANG->line('category_groups'))).
  2927. $DSP->crumb_item($title);
  2928. $DSP->body = $r;
  2929. }
  2930. /* END */
  2931. /** -----------------------------------------------------------
  2932. /** Create/update category group
  2933. /** -----------------------------------------------------------*/
  2934. // This function receives the submission from the group
  2935. // form and stores it in the database
  2936. //-----------------------------------------------------------
  2937. function update_category_group()
  2938. {
  2939. global $DSP, $IN, $DB, $LOG, $LANG, $PREFS;
  2940. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  2941. {
  2942. return $DSP->no_access_message();
  2943. }
  2944. // If the $group_id variable is present we are editing an
  2945. // existing group, otherwise we are creating a new one
  2946. $edit = (isset($_POST['group_id'])) ? TRUE : FALSE;
  2947. if ($_POST['group_name'] == '')
  2948. {
  2949. return $this->edit_category_group_form();
  2950. }
  2951. // this should never happen, but protect ourselves!
  2952. if ( ! isset($_POST['field_html_formatting']) OR ! in_array($_POST['field_html_formatting'], array('all', 'none', 'safe')))
  2953. {
  2954. return $this->edit_category_group_form();
  2955. }
  2956. // check for bad characters in group name
  2957. if ( ! preg_match("#^[a-zA-Z0-9_\-/\s]+$#i", $_POST['group_name']))
  2958. {
  2959. return $DSP->error_message($LANG->line('illegal_characters'));
  2960. }
  2961. // Is the group name taken?
  2962. $sql = "SELECT count(*) as count FROM exp_category_groups WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND group_name = '".$DB->escape_str($_POST['group_name'])."'";
  2963. if ($edit == TRUE)
  2964. {
  2965. $sql .= " AND group_id != '".$DB->escape_str($_POST['group_id'])."'";
  2966. }
  2967. $query = $DB->query($sql);
  2968. if ($query->row['count'] > 0)
  2969. {
  2970. return $DSP->error_message($LANG->line('taken_category_group_name'));
  2971. }
  2972. // make data array of variables from our POST data, so we can ignore
  2973. // some unwanted keys before INSERTing / UPDATEing
  2974. $data = array();
  2975. foreach ($_POST as $key => $val)
  2976. {
  2977. if (strpos($key, 'can_edit_categories_') !== FALSE OR strpos($key, 'can_delete_categories_') !== FALSE)
  2978. {
  2979. continue;
  2980. }
  2981. $data[$key] = $val;
  2982. }
  2983. // Set our pipe delimited privileges for edit / delete
  2984. if (isset($data['can_edit_categories']) and is_array($data['can_edit_categories']))
  2985. {
  2986. $data['can_edit_categories'] = implode('|', $data['can_edit_categories']);
  2987. }
  2988. else
  2989. {
  2990. $data['can_edit_categories'] = '';
  2991. }
  2992. if (isset($data['can_delete_categories']) and is_array($data['can_delete_categories']))
  2993. {
  2994. $data['can_delete_categories'] = implode('|', $data['can_delete_categories']);
  2995. }
  2996. else
  2997. {
  2998. $data['can_delete_categories'] = '';
  2999. }
  3000. // Construct the query based on whether we are updating or inserting
  3001. if ($edit == FALSE)
  3002. {
  3003. unset($data['group_id']);
  3004. $data['site_id'] = $PREFS->ini('site_id');
  3005. $sql = $DB->insert_string('exp_category_groups', $data);
  3006. $success_msg = $LANG->line('category_group_created');
  3007. $crumb = $DSP->crumb_item($LANG->line('new_weblog'));
  3008. $LOG->log_action($LANG->line('category_group_created').$DSP->nbs(2).$data['group_name']);
  3009. }
  3010. else
  3011. {
  3012. $sql = $DB->update_string('exp_category_groups', $data, 'group_id='.$DB->escape_str($data['group_id']));
  3013. $success_msg = $LANG->line('category_group_updated');
  3014. $crumb = $DSP->crumb_item($LANG->line('update'));
  3015. }
  3016. $DB->query($sql);
  3017. $message = $DSP->div('box');
  3018. $message .= $DSP->qdiv('defaultBold', $success_msg.NBS.$DSP->qspan('success', $data['group_name']));
  3019. if ($edit == FALSE)
  3020. {
  3021. $query = $DB->query("SELECT weblog_id from exp_weblogs WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND is_user_blog = 'n'");
  3022. if ($query->num_rows > 0)
  3023. {
  3024. $message .= $DSP->qdiv('itemWrapper', $DSP->qdiv('alert', $LANG->line('assign_group_to_weblog')));
  3025. if ($query->num_rows == 1)
  3026. {
  3027. $link = 'C=admin'.AMP.'M=blog_admin'.AMP.'P=group_prefs'.AMP.'weblog_id='.$query->row['weblog_id'];
  3028. }
  3029. else
  3030. {
  3031. $link = 'C=admin'.AMP.'M=blog_admin'.AMP.'P=blog_list';
  3032. }
  3033. $message .= $DSP->qdiv('itemWrapper', $DSP->anchor(BASE.AMP.$link, $LANG->line('click_to_assign_group')));
  3034. }
  3035. }
  3036. $message .= $DSP->div_c();
  3037. return $this->category_overview($message);
  3038. }
  3039. /* END */
  3040. /** -----------------------------------------------------------
  3041. /** Delete category group confirm
  3042. /** -----------------------------------------------------------*/
  3043. // Warning message if you try to delete a category group
  3044. //-----------------------------------------------------------
  3045. function delete_category_group_conf()
  3046. {
  3047. global $DSP, $IN, $DB, $LANG;
  3048. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  3049. {
  3050. return $DSP->no_access_message();
  3051. }
  3052. if (($group_id = $IN->GBL('group_id')) === FALSE OR ! is_numeric($group_id))
  3053. {
  3054. return FALSE;
  3055. }
  3056. $query = $DB->query("SELECT group_name FROM exp_category_groups WHERE group_id = '".$DB->escape_str($group_id)."'");
  3057. $DSP->title = $LANG->line('delete_group');
  3058. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  3059. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=categories', $LANG->line('category_groups'))).
  3060. $DSP->crumb_item($LANG->line('delete_group'));
  3061. $DSP->body = $DSP->delete_confirmation(
  3062. array(
  3063. 'url' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=delete_group'.AMP.'group_id='.$group_id,
  3064. 'heading' => 'delete_group',
  3065. 'message' => 'delete_cat_group_confirmation',
  3066. 'item' => $query->row['group_name'],
  3067. 'extra' => '',
  3068. 'hidden' => array('group_id' => $group_id)
  3069. )
  3070. );
  3071. }
  3072. /* END */
  3073. /** -----------------------------------------------------------
  3074. /** Delete categroy group
  3075. /** -----------------------------------------------------------*/
  3076. // This function deletes the category group and all
  3077. // associated catetgories
  3078. //-----------------------------------------------------------
  3079. function delete_category_group()
  3080. {
  3081. global $DSP, $IN, $DB, $LOG, $LANG, $FNS;
  3082. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  3083. {
  3084. return $DSP->no_access_message();
  3085. }
  3086. if (($group_id = $IN->GBL('group_id')) === FALSE OR ! is_numeric($group_id))
  3087. {
  3088. return FALSE;
  3089. }
  3090. $query = $DB->query("SELECT group_name, group_id FROM exp_category_groups WHERE group_id = '".$DB->escape_str($group_id)."'");
  3091. if ($query->num_rows == 0)
  3092. {
  3093. return FALSE;
  3094. }
  3095. $name = $query->row['group_name'];
  3096. $group_id = $query->row['group_id'];
  3097. /** ---------------------------------------
  3098. /** Delete from exp_category_posts
  3099. /** ---------------------------------------*/
  3100. $query = $DB->query("SELECT cat_id FROM exp_categories WHERE group_id = {$group_id}");
  3101. if ($query->num_rows > 0)
  3102. {
  3103. $cat_ids = array();
  3104. foreach ($query->result as $row)
  3105. {
  3106. $cat_ids[] = $row['cat_id'];
  3107. }
  3108. $DB->query("DELETE FROM exp_category_posts WHERE cat_id IN (".implode(',', $cat_ids).")");
  3109. }
  3110. $DB->query("DELETE FROM exp_category_groups WHERE group_id = {$group_id}");
  3111. $DB->query("DELETE FROM exp_categories WHERE group_id = {$group_id}");
  3112. /** ---------------------------------------
  3113. /** Delete category field data
  3114. /** ---------------------------------------*/
  3115. $query = $DB->query("SELECT field_id FROM exp_category_fields WHERE group_id = {$group_id}");
  3116. if ($query->num_rows > 0)
  3117. {
  3118. $field_ids = array();
  3119. foreach ($query->result as $row)
  3120. {
  3121. $field_ids[] = $row['field_id'];
  3122. }
  3123. foreach ($field_ids as $field_id)
  3124. {
  3125. $DB->query("ALTER TABLE exp_category_field_data DROP COLUMN field_id_{$field_id}");
  3126. $DB->query("ALTER TABLE exp_category_field_data DROP COLUMN field_ft_{$field_id}");
  3127. }
  3128. }
  3129. $DB->query("DELETE FROM exp_category_fields WHERE group_id = {$group_id}");
  3130. $DB->query("DELETE FROM exp_category_field_data WHERE group_id = {$group_id}");
  3131. $message = $DSP->qdiv('box', $DSP->qspan('success', $LANG->line('category_group_deleted')).NBS.NBS.'<b>'.$name.'</b>');
  3132. $LOG->log_action($LANG->line('category_group_deleted').$DSP->nbs(2).$name);
  3133. $FNS->clear_caching('all', '', TRUE);
  3134. return $this->category_overview($message);
  3135. }
  3136. /* END */
  3137. /** -----------------------------------------------------------
  3138. /** Category tree
  3139. /** -----------------------------------------------------------*/
  3140. // This function (and the next) create a hierarchical tree
  3141. // of categories.
  3142. //-----------------------------------------------------------
  3143. function category_tree($type = 'text', $group_id = '', $p_id = '', $sort_order = 'a')
  3144. {
  3145. global $DSP, $IN, $REGX, $DB, $PREFS, $LANG;
  3146. // Fetch category group ID number
  3147. if ($group_id == '')
  3148. {
  3149. if (($group_id = $IN->GBL('group_id')) === FALSE OR ! is_numeric($group_id))
  3150. {
  3151. return FALSE;
  3152. }
  3153. }
  3154. elseif ( ! is_numeric($group_id))
  3155. {
  3156. return FALSE;
  3157. }
  3158. // Fetch category groups
  3159. $sql = "SELECT cat_name, cat_id, parent_id FROM exp_categories WHERE group_id = '".$DB->escape_str($group_id)."' ";
  3160. $sql .= ($sort_order == 'a') ? "ORDER BY parent_id, cat_name" : "ORDER BY parent_id, cat_order";
  3161. $query = $DB->query($sql);
  3162. if ($query->num_rows == 0)
  3163. {
  3164. return FALSE;
  3165. }
  3166. // Assign the query result to a multi-dimensional array
  3167. foreach($query->result as $row)
  3168. {
  3169. $cat_array[$row['cat_id']] = array($row['parent_id'], $row['cat_name']);
  3170. }
  3171. if ($type == 'data')
  3172. {
  3173. return $cat_array;
  3174. }
  3175. $up = '<img src="'.PATH_CP_IMG.'arrow_up.gif" border="0" width="16" height="16" alt="" title="" />';
  3176. $down = '<img src="'.PATH_CP_IMG.'arrow_down.gif" border="0" width="16" height="16" alt="" title="" />';
  3177. // Build our output...
  3178. $can_delete = TRUE;
  3179. if ($IN->GBL('Z') == 1)
  3180. {
  3181. if ($DSP->allowed_group('can_delete_categories') OR $DSP->allowed_group('can_admin_weblogs'))
  3182. {
  3183. $can_delete = TRUE;
  3184. }
  3185. else
  3186. {
  3187. $can_delete = FALSE;
  3188. }
  3189. }
  3190. $zurl = ($IN->GBL('Z') == 1) ? AMP.'Z=1' : '';
  3191. $zurl .= ($IN->GBL('cat_group') !== FALSE) ? AMP.'cat_group='.$IN->GBL('cat_group') : '';
  3192. $zurl .= ($IN->GBL('integrated') !== FALSE) ? AMP.'integrated='.$IN->GBL('integrated') : '';
  3193. foreach($cat_array as $key => $val)
  3194. {
  3195. if (0 == $val['0'])
  3196. {
  3197. if ($type == 'table')
  3198. {
  3199. if ($can_delete == TRUE)
  3200. $delete = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=del_category_conf'.AMP.'cat_id='.$key.$zurl, $LANG->line('delete'));
  3201. else
  3202. $delete = $LANG->line('delete');
  3203. $this->categories[] =
  3204. $DSP->table_qrow( 'tableCellTwo',
  3205. array($key,
  3206. $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=cat_order'.AMP.'cat_id='.$key.AMP.'group_id='.$group_id.AMP.'order=up'.$zurl, $up).NBS.
  3207. $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=cat_order'.AMP.'cat_id='.$key.AMP.'group_id='.$group_id.AMP.'order=down'.$zurl, $down),
  3208. $DSP->qdiv('defaultBold', NBS.$val['1']),
  3209. $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=edit_category'.AMP.'cat_id='.$key.AMP.'group_id='.$group_id.$zurl, $LANG->line('edit')),
  3210. $delete
  3211. )
  3212. );
  3213. }
  3214. else
  3215. {
  3216. $this->categories[] = $DSP->input_select_option($key, $val['1'], ($key == $p_id) ? '1' : '');
  3217. }
  3218. $this->category_subtree($key, $cat_array, $group_id, $depth=0, $type, $p_id);
  3219. }
  3220. }
  3221. }
  3222. /* END */
  3223. /** --------------------------------------
  3224. /** Category sub-tree
  3225. /** --------------------------------------*/
  3226. function category_subtree($cat_id, $cat_array, $group_id, $depth, $type, $p_id)
  3227. {
  3228. global $DSP, $IN, $DB, $REGX, $LANG, $PREFS;
  3229. if ($type == 'table')
  3230. {
  3231. $spcr = '<img src="'.PATH_CP_IMG.'clear.gif" border="0" width="24" height="14" alt="" title="" />';
  3232. $indent = $spcr.'<img src="'.PATH_CP_IMG.'cat_marker.gif" border="0" width="18" height="14" alt="" title="" />';
  3233. }
  3234. else
  3235. {
  3236. $spcr = '&nbsp;';
  3237. $indent = $spcr.$spcr.$spcr.$spcr;
  3238. }
  3239. $up = '<img src="'.PATH_CP_IMG.'arrow_up.gif" border="0" width="16" height="16" alt="" title="" />';
  3240. $down = '<img src="'.PATH_CP_IMG.'arrow_down.gif" border="0" width="16" height="16" alt="" title="" />';
  3241. if ($depth == 0)
  3242. {
  3243. $depth = 1;
  3244. }
  3245. else
  3246. {
  3247. $indent = str_repeat($spcr, $depth+1).$indent;
  3248. $depth = ($type == 'table') ? $depth + 1 : $depth + 4;
  3249. }
  3250. $can_delete = TRUE;
  3251. if ($IN->GBL('Z') == 1)
  3252. {
  3253. if ($DSP->allowed_group('can_delete_categories') OR $DSP->allowed_group('can_admin_weblogs'))
  3254. {
  3255. $can_delete = TRUE;
  3256. }
  3257. else
  3258. {
  3259. $can_delete = FALSE;
  3260. }
  3261. }
  3262. $zurl = ($IN->GBL('Z') == 1) ? AMP.'Z=1' : '';
  3263. $zurl .= ($IN->GBL('cat_group') !== FALSE) ? AMP.'cat_group='.$IN->GBL('cat_group') : '';
  3264. $zurl .= ($IN->GBL('integrated') !== FALSE) ? AMP.'integrated='.$IN->GBL('integrated') : '';
  3265. foreach ($cat_array as $key => $val)
  3266. {
  3267. if ($cat_id == $val['0'])
  3268. {
  3269. $pre = ($depth > 2) ? "&nbsp;" : '';
  3270. if ($type == 'table')
  3271. {
  3272. if ($can_delete == TRUE)
  3273. $delete = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=del_category_conf'.AMP.'cat_id='.$key.$zurl, $LANG->line('delete'));
  3274. else
  3275. $delete = $LANG->line('delete');
  3276. $this->categories[] =
  3277. $DSP->table_qrow( 'tableCellTwo',
  3278. array($key,
  3279. $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=cat_order'.AMP.'cat_id='.$key.AMP.'group_id='.$group_id.AMP.'order=up'.$zurl, $up).NBS.
  3280. $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=cat_order'.AMP.'cat_id='.$key.AMP.'group_id='.$group_id.AMP.'order=down'.$zurl, $down),
  3281. $DSP->qdiv('defaultBold', $pre.$indent.NBS.$val['1']),
  3282. $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=edit_category'.AMP.'cat_id='.$key.AMP.'group_id='.$group_id.$zurl, $LANG->line('edit')),
  3283. $delete
  3284. )
  3285. );
  3286. }
  3287. else
  3288. {
  3289. $this->categories[] = $DSP->input_select_option($key, $pre.$indent.NBS.$val['1'], ($key == $p_id) ? '1' : '');
  3290. }
  3291. $this->category_subtree($key, $cat_array, $group_id, $depth, $type, $p_id);
  3292. }
  3293. }
  3294. }
  3295. /* END */
  3296. /** --------------------------------------
  3297. /** Change Category Order
  3298. /** --------------------------------------*/
  3299. function change_category_order()
  3300. {
  3301. global $DB, $FNS, $DSP, $IN;
  3302. if ($IN->GBL('Z') == 1)
  3303. {
  3304. if ( ! $DSP->allowed_group('can_admin_weblogs') AND ! $DSP->allowed_group('can_edit_categories'))
  3305. {
  3306. return $DSP->no_access_message();
  3307. }
  3308. }
  3309. else
  3310. {
  3311. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  3312. {
  3313. return $DSP->no_access_message();
  3314. }
  3315. }
  3316. // Fetch required globals
  3317. foreach (array('cat_id', 'group_id', 'order') as $val)
  3318. {
  3319. if ( ! isset($_GET[$val]))
  3320. {
  3321. return FALSE;
  3322. }
  3323. $$val = $_GET[$val];
  3324. }
  3325. $zurl = ($IN->GBL('Z') == 1) ? AMP.'Z=1' : '';
  3326. $zurl .= ($IN->GBL('cat_group') !== FALSE) ? AMP.'cat_group='.$IN->GBL('cat_group') : '';
  3327. $zurl .= ($IN->GBL('integrated') !== FALSE) ? AMP.'integrated='.$IN->GBL('integrated') : '';
  3328. // Return Location
  3329. $return = BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=category_editor'.AMP.'group_id='.$group_id.$zurl;
  3330. // Fetch the parent ID
  3331. $query = $DB->query("SELECT parent_id FROM exp_categories WHERE cat_id = '".$DB->escape_str($cat_id)."'");
  3332. $parent_id = $query->row['parent_id'];
  3333. // Is the requested category already at the beginning/end of the list?
  3334. $dir = ($order == 'up') ? 'asc' : 'desc';
  3335. $query = $DB->query("SELECT cat_id FROM exp_categories WHERE group_id = '".$DB->escape_str($group_id)."' AND parent_id = '".$DB->escape_str($parent_id)."' ORDER BY cat_order {$dir} LIMIT 1");
  3336. if ($query->row['cat_id'] == $cat_id)
  3337. {
  3338. $FNS->redirect($return);
  3339. exit;
  3340. }
  3341. // Fetch all the categories in the parent
  3342. $query = $DB->query("SELECT cat_id, cat_order FROM exp_categories WHERE group_id = '".$DB->escape_str($group_id)."' AND parent_id = '".$DB->escape_str($parent_id)."' ORDER BY cat_order asc");
  3343. // If there is only one category, there is nothing to re-order
  3344. if ($query->num_rows <= 1)
  3345. {
  3346. $FNS->redirect($return);
  3347. exit;
  3348. }
  3349. // Assign category ID numbers in an array except the category being shifted.
  3350. // We will also set the position number of the category being shifted, which
  3351. // we'll use in array_shift()
  3352. $flag = '';
  3353. $i = 1;
  3354. $cats = array();
  3355. foreach ($query->result as $row)
  3356. {
  3357. if ($cat_id == $row['cat_id'])
  3358. {
  3359. $flag = ($order == 'down') ? $i+1 : $i-1;
  3360. }
  3361. else
  3362. {
  3363. $cats[] = $row['cat_id'];
  3364. }
  3365. $i++;
  3366. }
  3367. array_splice($cats, ($flag -1), 0, $cat_id);
  3368. // Update the category order for all the categories within the given parent
  3369. $i = 1;
  3370. foreach ($cats as $val)
  3371. {
  3372. $DB->query("UPDATE exp_categories SET cat_order = '$i' WHERE cat_id = '$val'");
  3373. $i++;
  3374. }
  3375. // Switch to custom order
  3376. $DB->query("UPDATE exp_category_groups SET sort_order = 'c' WHERE group_id = '".$DB->escape_str($group_id)."'");
  3377. $FNS->redirect($return);
  3378. exit;
  3379. }
  3380. /* END */
  3381. /** -----------------------------------------------------------
  3382. /** Category management page
  3383. /** -----------------------------------------------------------*/
  3384. // This function shows the list of current categories, as
  3385. // well as the form used to submit a new category
  3386. //-----------------------------------------------------------
  3387. function category_manager($group_id = '', $update = FALSE)
  3388. {
  3389. global $DSP, $IN, $DB, $LANG, $SESS;
  3390. if ($IN->GBL('Z') == 1)
  3391. {
  3392. if ( ! $DSP->allowed_group('can_admin_weblogs') AND ! $DSP->allowed_group('can_edit_categories'))
  3393. {
  3394. return $DSP->no_access_message();
  3395. }
  3396. }
  3397. else
  3398. {
  3399. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  3400. {
  3401. return $DSP->no_access_message();
  3402. }
  3403. }
  3404. if ($group_id == '')
  3405. {
  3406. if (($group_id = $IN->GBL('group_id')) === FALSE OR ! is_numeric($group_id))
  3407. {
  3408. return FALSE;
  3409. }
  3410. }
  3411. /** ---------------------------------------
  3412. /** Check discrete privileges
  3413. /** ---------------------------------------*/
  3414. if ($IN->GBL('Z') == 1)
  3415. {
  3416. $query = $DB->query("SELECT can_edit_categories FROM exp_category_groups WHERE group_id = '".$DB->escape_str($group_id)."'");
  3417. if ($query->num_rows == 0)
  3418. {
  3419. return FALSE;
  3420. }
  3421. $can_edit = explode('|', rtrim($query->row['can_edit_categories'], '|'));
  3422. if ($SESS->userdata['group_id'] != 1 AND ! in_array($SESS->userdata['group_id'], $can_edit))
  3423. {
  3424. return $DSP->no_access_message();
  3425. }
  3426. }
  3427. $zurl = ($IN->GBL('Z') == 1) ? AMP.'Z=1' : '';
  3428. $zurl .= ($IN->GBL('cat_group') !== FALSE) ? AMP.'cat_group='.$IN->GBL('cat_group') : '';
  3429. $zurl .= ($IN->GBL('integrated') !== FALSE) ? AMP.'integrated='.$IN->GBL('integrated') : '';
  3430. $query = $DB->query("SELECT group_name, sort_order FROM exp_category_groups WHERE group_id = '".$DB->escape_str($group_id)."'");
  3431. $group_name = $query->row['group_name'];
  3432. $sort_order = $query->row['sort_order'];
  3433. $r = '';
  3434. if ($IN->GBL('Z') == 1)
  3435. {
  3436. $url = BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=edit_category'.AMP.'group_id='.$group_id.$zurl;
  3437. $js = ' onclick="navjump(\''.$url.'\');" onmouseover="navCrumbOn();" onmouseout="navCrumbOff();" ';
  3438. $r .= $DSP->anchor($url, '<div class="crumblinksR" style="width:300px;margin-left:auto;" id="rcrumb" '.$js.'>'.$DSP->qdiv('itemWrapper', $LANG->line('new_category')).'</div>');
  3439. }
  3440. $r .= $DSP->qdiv('tableHeading', $group_name);
  3441. if ($update != FALSE)
  3442. {
  3443. $r .= $DSP->qdiv('box', $DSP->qspan('success', $LANG->line('category_updated')));
  3444. }
  3445. // Fetch the category tree
  3446. $this->category_tree('table', $group_id, '', $sort_order);
  3447. if (count($this->categories) == 0)
  3448. {
  3449. $r .= $DSP->qdiv('box', $DSP->qdiv('highlight', $LANG->line('no_category_message')));
  3450. }
  3451. else
  3452. {
  3453. $r .= $DSP->table('tableBorder', '0', '0').
  3454. $DSP->tr().
  3455. $DSP->table_qcell('tableHeadingAlt', 'ID', '2%').
  3456. $DSP->table_qcell('tableHeadingAlt', $LANG->line('order'), '8%').
  3457. $DSP->table_qcell('tableHeadingAlt', $LANG->line('category_name'), '50%').
  3458. $DSP->table_qcell('tableHeadingAlt', $LANG->line('edit'), '20%').
  3459. $DSP->table_qcell('tableHeadingAlt', $LANG->line('delete'), '20%');
  3460. $r .= $DSP->tr_c();
  3461. foreach ($this->categories as $val)
  3462. {
  3463. $prefix = (strlen($val['0']) == 1) ? NBS.NBS : NBS;
  3464. $r .= $val;
  3465. }
  3466. $r .= $DSP->table_c();
  3467. $r .= $DSP->qdiv('defaultSmall', '');
  3468. // Category order
  3469. if ($IN->GBL('Z') == FALSE)
  3470. {
  3471. $r .= $DSP->form_open(array('action' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=global_cat_order'.AMP.'group_id='.$group_id.$zurl));
  3472. $r .= $DSP->div('box320');
  3473. $r .= $DSP->qdiv('defaultBold', $LANG->line('global_sort_order'));
  3474. $r .= $DSP->div('itemWrapper');
  3475. $r .= $DSP->input_radio('sort_order', 'a', ($sort_order == 'a') ? 1 : '').NBS.$LANG->line('alpha').NBS.NBS.$DSP->input_radio('sort_order', 'c', ($sort_order != 'a') ? 1 : '').NBS.$LANG->line('custom');
  3476. $r .= NBS.NBS.NBS.$DSP->input_submit($LANG->line('update'));
  3477. $r .= $DSP->div_c();
  3478. $r .= $DSP->div_c();
  3479. $r .= $DSP->form_close();
  3480. }
  3481. }
  3482. // Build category tree for javascript replacement
  3483. if ($IN->GBL('Z') == 1)
  3484. {
  3485. if ( ! class_exists('Publish'))
  3486. {
  3487. require PATH_CP.'cp.publish'.EXT;
  3488. }
  3489. $PUB = new Publish();
  3490. $PUB->category_tree(($IN->GBL('cat_group') !== FALSE) ? $IN->GBL('cat_group') : $IN->GBL('group_id'), 'new', '', '', ($IN->GBL('integrated') == 'y') ? 'y' : 'n');
  3491. $cm = "";
  3492. foreach ($PUB->categories as $val)
  3493. {
  3494. $cm .= $val;
  3495. }
  3496. $cm = preg_replace("/(\r\n)|(\r)|(\n)/", '', $cm);
  3497. $DSP->extra_header = '
  3498. <script type="text/javascript">
  3499. function update_cats()
  3500. {
  3501. var str = "'.$cm.'";
  3502. opener.swap_categories(str);
  3503. window.close();
  3504. }
  3505. </script>';
  3506. // $r .= $DSP->qdiv('itemWrapper', $DSP->qdiv('defaultCenter', '<a href="javascript:update_cats();"><b>'.$LANG->line('update_publish_cats').'</b></a>'));
  3507. $r .= '<form>';
  3508. $r .= $DSP->qdiv('itemWrapper', $DSP->qdiv('defaultCenter', '<input type="submit" value="'.NBS.$LANG->line('update_publish_cats').NBS.'" onclick="update_cats();"/>' ));
  3509. $r .= '</form>';
  3510. }
  3511. // Assign output data
  3512. $DSP->title = $LANG->line('categories');
  3513. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  3514. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=categories', $LANG->line('category_groups'))).
  3515. $DSP->crumb_item($LANG->line('categories'));
  3516. $DSP->right_crumb($LANG->line('new_category'), BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=edit_category'.AMP.'group_id='.$group_id);
  3517. $DSP->body = $r;
  3518. }
  3519. /* END */
  3520. /** -----------------------------------
  3521. /** Set Global Category Order
  3522. /** -----------------------------------*/
  3523. function global_category_order()
  3524. {
  3525. global $DSP, $IN, $DB, $FNS;
  3526. if ($IN->GBL('Z') == 1)
  3527. {
  3528. if ( ! $DSP->allowed_group('can_admin_weblogs') AND ! $DSP->allowed_group('can_edit_categories'))
  3529. {
  3530. return $DSP->no_access_message();
  3531. }
  3532. }
  3533. else
  3534. {
  3535. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  3536. {
  3537. return $DSP->no_access_message();
  3538. }
  3539. }
  3540. if (($group_id = $IN->GBL('group_id')) === FALSE OR ! is_numeric($group_id))
  3541. {
  3542. return FALSE;
  3543. }
  3544. $order = ($_POST['sort_order'] == 'a') ? 'a' : 'c';
  3545. $query = $DB->query("SELECT sort_order FROM exp_category_groups WHERE group_id = '".$DB->escape_str($group_id)."'");
  3546. if ($order == 'a')
  3547. {
  3548. if ( ! isset($_POST['override']))
  3549. {
  3550. return $this->global_category_order_confirm();
  3551. }
  3552. else
  3553. {
  3554. $this->reorder_cats_alphabetically();
  3555. }
  3556. }
  3557. $DB->query("UPDATE exp_category_groups SET sort_order = '$order' WHERE group_id = '".$DB->escape_str($group_id)."'");
  3558. $FNS->redirect(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=category_editor'.AMP.'group_id='.$group_id);
  3559. exit;
  3560. }
  3561. /* END */
  3562. /** --------------------------------------
  3563. /** Category order change confirm
  3564. /** --------------------------------------*/
  3565. function global_category_order_confirm()
  3566. {
  3567. global $DSP, $IN, $DB, $LANG;
  3568. if ($IN->GBL('Z') == 1)
  3569. {
  3570. if ( ! $DSP->allowed_group('can_admin_weblogs') AND ! $DSP->allowed_group('can_edit_categories'))
  3571. {
  3572. return $DSP->no_access_message();
  3573. }
  3574. }
  3575. else
  3576. {
  3577. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  3578. {
  3579. return $DSP->no_access_message();
  3580. }
  3581. }
  3582. if (($group_id = $IN->GBL('group_id')) === FALSE OR ! is_numeric($group_id))
  3583. {
  3584. return FALSE;
  3585. }
  3586. $DSP->title = $LANG->line('global_sort_order');
  3587. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  3588. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=categories', $LANG->line('category_groups'))).
  3589. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=category_editor'.AMP.'group_id='.$group_id, $LANG->line('categories'))).
  3590. $DSP->crumb_item($LANG->line('global_sort_order'));
  3591. $DSP->body = $DSP->form_open(array('action' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=global_cat_order'.AMP.'group_id='.$group_id))
  3592. .$DSP->input_hidden('sort_order', $_POST['sort_order'])
  3593. .$DSP->input_hidden('override', 1)
  3594. .$DSP->qdiv('tableHeading', $LANG->line('global_sort_order'))
  3595. .$DSP->div('box')
  3596. .$DSP->qdiv('defaultBold', $LANG->line('category_order_confirm_text'))
  3597. .$DSP->qdiv('alert', BR.$LANG->line('category_sort_warning').BR.BR)
  3598. .$DSP->div_c()
  3599. .$DSP->qdiv('itemWrapper', $DSP->input_submit($LANG->line('update')))
  3600. .$DSP->form_close();
  3601. }
  3602. /* END */
  3603. /** --------------------------------
  3604. /** Re-order Categories Alphabetically
  3605. /** --------------------------------*/
  3606. function reorder_cats_alphabetically()
  3607. {
  3608. global $DSP, $IN, $DB;
  3609. if ($IN->GBL('Z') == 1)
  3610. {
  3611. if ( ! $DSP->allowed_group('can_admin_weblogs') AND ! $DSP->allowed_group('can_edit_categories'))
  3612. {
  3613. return $DSP->no_access_message();
  3614. }
  3615. }
  3616. else
  3617. {
  3618. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  3619. {
  3620. return $DSP->no_access_message();
  3621. }
  3622. }
  3623. if (($group_id = $IN->GBL('group_id')) === FALSE OR ! is_numeric($group_id))
  3624. {
  3625. return FALSE;
  3626. }
  3627. $data = $this->process_category_group($group_id);
  3628. if (count($data) == 0)
  3629. {
  3630. return FALSE;
  3631. }
  3632. foreach($data as $cat_id => $cat_data)
  3633. {
  3634. $DB->query("UPDATE exp_categories SET cat_order = '{$cat_data['1']}' WHERE cat_id = '{$cat_id}'");
  3635. }
  3636. return TRUE;
  3637. }
  3638. /* END */
  3639. /** --------------------------------
  3640. /** Process nested category group
  3641. /** --------------------------------*/
  3642. function process_category_group($group_id)
  3643. {
  3644. global $DB;
  3645. $sql = "SELECT cat_name, cat_id, parent_id FROM exp_categories WHERE group_id ='$group_id' ORDER BY parent_id, cat_name";
  3646. $query = $DB->query($sql);
  3647. if ($query->num_rows == 0)
  3648. {
  3649. return FALSE;
  3650. }
  3651. foreach($query->result as $row)
  3652. {
  3653. $this->cat_update[$row['cat_id']] = array($row['parent_id'], '1', $row['cat_name']);
  3654. }
  3655. $order = 0;
  3656. foreach($this->cat_update as $key => $val)
  3657. {
  3658. if (0 == $val['0'])
  3659. {
  3660. $order++;
  3661. $this->cat_update[$key]['1'] = $order;
  3662. $this->process_subcategories($key); // Sends parent_id
  3663. }
  3664. }
  3665. return $this->cat_update;
  3666. }
  3667. /* END */
  3668. /** --------------------------------
  3669. /** Process Subcategories
  3670. /** --------------------------------*/
  3671. function process_subcategories($parent_id)
  3672. {
  3673. $order = 0;
  3674. foreach($this->cat_update as $key => $val)
  3675. {
  3676. if ($parent_id == $val['0'])
  3677. {
  3678. $order++;
  3679. $this->cat_update[$key]['1'] = $order;
  3680. $this->process_subcategories($key);
  3681. }
  3682. }
  3683. }
  3684. /* END */
  3685. /** -----------------------------------------------------------
  3686. /** New / Edit category form
  3687. /** -----------------------------------------------------------*/
  3688. // This function displays an existing category in a form
  3689. // so that it can be edited.
  3690. //-----------------------------------------------------------
  3691. function edit_category_form()
  3692. {
  3693. global $DSP, $EXT, $IN, $DB, $REGX, $LANG, $PREFS, $SESS;
  3694. if ($IN->GBL('Z') == 1)
  3695. {
  3696. if ( ! $DSP->allowed_group('can_admin_weblogs') AND ! $DSP->allowed_group('can_edit_categories'))
  3697. {
  3698. return $DSP->no_access_message();
  3699. }
  3700. }
  3701. else
  3702. {
  3703. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  3704. {
  3705. return $DSP->no_access_message();
  3706. }
  3707. }
  3708. if (($group_id = $IN->GBL('group_id')) === FALSE OR ! is_numeric($group_id))
  3709. {
  3710. return $DSP->no_access_message();
  3711. }
  3712. /** ---------------------------------------
  3713. /** Check discrete privileges
  3714. /** ---------------------------------------*/
  3715. if ($IN->GBL('Z') == 1)
  3716. {
  3717. $query = $DB->query("SELECT can_edit_categories FROM exp_category_groups WHERE group_id = '".$DB->escape_str($group_id)."'");
  3718. if ($query->num_rows == 0)
  3719. {
  3720. return FALSE;
  3721. }
  3722. $can_edit = explode('|', rtrim($query->row['can_edit_categories'], '|'));
  3723. if ($SESS->userdata['group_id'] != 1 AND ! in_array($SESS->userdata['group_id'], $can_edit))
  3724. {
  3725. return $DSP->no_access_message();
  3726. }
  3727. }
  3728. $cat_id = $IN->GBL('cat_id');
  3729. // Get the category sort order for the parent select field later on
  3730. $query = $DB->query("SELECT sort_order FROM exp_category_groups WHERE group_id = '".$DB->escape_str($group_id)."'");
  3731. $sort_order = $query->row['sort_order'];
  3732. $default = array('cat_name', 'cat_url_title', 'cat_description', 'cat_image', 'cat_id', 'parent_id');
  3733. if ($cat_id)
  3734. {
  3735. $query = $DB->query("SELECT cat_id, cat_name, cat_url_title, cat_description, cat_image, group_id, parent_id FROM exp_categories WHERE cat_id = '$cat_id'");
  3736. if ($query->num_rows == 0)
  3737. {
  3738. return $DSP->no_access_message();
  3739. }
  3740. foreach ($default as $val)
  3741. {
  3742. $$val = $query->row[$val];
  3743. }
  3744. }
  3745. else
  3746. {
  3747. foreach ($default as $val)
  3748. {
  3749. $$val = '';
  3750. }
  3751. }
  3752. // Build our output
  3753. $title = ( ! $cat_id) ? 'new_category' : 'edit_category';
  3754. $zurl = ($IN->GBL('Z') == 1) ? AMP.'Z=1' : '';
  3755. $zurl .= ($IN->GBL('cat_group') !== FALSE) ? AMP.'cat_group='.$IN->GBL('cat_group') : '';
  3756. $zurl .= ($IN->GBL('integrated') !== FALSE) ? AMP.'integrated='.$IN->GBL('integrated') : '';
  3757. $DSP->title = $LANG->line($title);
  3758. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  3759. $DSP->crumb_item($DSP->anchor( BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=categories', $LANG->line('category_groups'))).
  3760. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=category_editor'.AMP.'group_id='.$group_id, $LANG->line('categories'))).
  3761. $DSP->crumb_item($LANG->line($title));
  3762. $word_separator = $PREFS->ini('word_separator') != "dash" ? '_' : '-';
  3763. /** -------------------------------------
  3764. /** Create Foreign Character Conversion JS
  3765. /** -------------------------------------*/
  3766. /* -------------------------------------
  3767. /* 'foreign_character_conversion_array' hook.
  3768. /* - Allows you to use your own foreign character conversion array
  3769. /* - Added 1.6.0
  3770. */
  3771. if (isset($EXT->extensions['foreign_character_conversion_array']))
  3772. {
  3773. $foreign_characters = $EXT->call_extension('foreign_character_conversion_array');
  3774. }
  3775. else
  3776. {
  3777. $foreign_characters = array('223' => "ss", // ß
  3778. '224' => "a", '225' => "a", '226' => "a", '229' => "a",
  3779. '227' => "ae", '230' => "ae", '228' => "ae",
  3780. '231' => "c",
  3781. '232' => "e", // è
  3782. '233' => "e", // é
  3783. '234' => "e", // ê
  3784. '235' => "e", // ë
  3785. '236' => "i", '237' => "i", '238' => "i", '239' => "i",
  3786. '241' => "n",
  3787. '242' => "o", '243' => "o", '244' => "o", '245' => "o",
  3788. '246' => "oe", // ö
  3789. '249' => "u", '250' => "u", '251' => "u",
  3790. '252' => "ue", // ü
  3791. '255' => "y",
  3792. '257' => "aa",
  3793. '269' => "ch",
  3794. '275' => "ee",
  3795. '291' => "gj",
  3796. '299' => "ii",
  3797. '311' => "kj",
  3798. '316' => "lj",
  3799. '326' => "nj",
  3800. '353' => "sh",
  3801. '363' => "uu",
  3802. '382' => "zh",
  3803. '256' => "aa",
  3804. '268' => "ch",
  3805. '274' => "ee",
  3806. '290' => "gj",
  3807. '298' => "ii",
  3808. '310' => "kj",
  3809. '315' => "lj",
  3810. '325' => "nj",
  3811. '352' => "sh",
  3812. '362' => "uu",
  3813. '381' => "zh",
  3814. );
  3815. }
  3816. /*
  3817. /* -------------------------------------*/
  3818. $foreign_replace = '';
  3819. foreach($foreign_characters as $old => $new)
  3820. {
  3821. $foreign_replace .= "if (c == '$old') {NewTextTemp += '$new'; continue;}\n\t\t\t\t";
  3822. }
  3823. $r = <<<SCRIPPITYDOO
  3824. <script type="text/javascript">
  3825. <!--
  3826. /** ------------------------------------
  3827. /** Live URL Title Function
  3828. /** -------------------------------------*/
  3829. function liveUrlTitle()
  3830. {
  3831. var NewText = document.getElementById("cat_name").value;
  3832. NewText = NewText.toLowerCase();
  3833. var separator = "{$word_separator}";
  3834. // Foreign Character Attempt
  3835. var NewTextTemp = '';
  3836. for(var pos=0; pos<NewText.length; pos++)
  3837. {
  3838. var c = NewText.charCodeAt(pos);
  3839. if (c >= 32 && c < 128)
  3840. {
  3841. NewTextTemp += NewText.charAt(pos);
  3842. }
  3843. else
  3844. {
  3845. {$foreign_replace}
  3846. }
  3847. }
  3848. var multiReg = new RegExp(separator + '{2,}', 'g');
  3849. NewText = NewTextTemp;
  3850. NewText = NewText.replace('/<(.*?)>/g', '');
  3851. NewText = NewText.replace(/\s+/g, separator);
  3852. NewText = NewText.replace(/\//g, separator);
  3853. NewText = NewText.replace(/[^a-z0-9\-\._]/g,'');
  3854. NewText = NewText.replace(/\+/g, separator);
  3855. NewText = NewText.replace(multiReg, separator);
  3856. NewText = NewText.replace(/-$/g,'');
  3857. NewText = NewText.replace(/_$/g,'');
  3858. NewText = NewText.replace(/^_/g,'');
  3859. NewText = NewText.replace(/^-/g,'');
  3860. NewText = NewText.replace(/\.+$/g,'');
  3861. document.getElementById("cat_url_title").value = NewText;
  3862. }
  3863. -->
  3864. </script>
  3865. SCRIPPITYDOO;
  3866. $r .= $DSP->qdiv('tableHeading', $LANG->line($title));
  3867. $r .= $DSP->form_open(array('id' => 'category_form', 'action' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=update_category'.$zurl)).
  3868. $DSP->input_hidden('group_id', $group_id);
  3869. if ($cat_id)
  3870. {
  3871. $r .= $DSP->input_hidden('cat_id', $cat_id);
  3872. }
  3873. $r .= $DSP->div('box');
  3874. $r .= $DSP->div('itemWrapper').
  3875. $DSP->qdiv('itemWrapper', $DSP->qdiv('defaultBold', $DSP->required().NBS.$LANG->line('category_name', 'cat_name'))).
  3876. $DSP->input_text('cat_name', $cat_name, '20', '100', 'input', '400px', (( ! $cat_id) ? 'onkeyup="liveUrlTitle();"' : ''), TRUE).
  3877. $DSP->div_c();
  3878. $r .= $DSP->div('itemWrapper').
  3879. $DSP->qdiv('itemWrapper', $DSP->qdiv('defaultBold', $LANG->line('category_url_title', 'cat_url_title'))).
  3880. $DSP->input_text('cat_url_title', $cat_url_title, '20', '75', 'input', '400px', '', TRUE).
  3881. $DSP->div_c();
  3882. $r .= $DSP->div('itemWrapper').
  3883. $DSP->qdiv('itemWrapper', $DSP->qdiv('defaultBold', $LANG->line('category_description', 'cat_description'))).
  3884. $DSP->input_textarea('cat_description', $cat_description, 4, 'textarea', '400px').
  3885. $DSP->div_c();
  3886. $r .= $DSP->div('itemWrapper').
  3887. $DSP->qdiv('defaultBold', $LANG->line('category_image', 'cat_image')).
  3888. $DSP->qdiv('itemWrapper', $DSP->qdiv('', $LANG->line('category_img_blurb'))).
  3889. $DSP->input_text('cat_image', $cat_image, '40', '120', 'input', '400px').
  3890. $DSP->div_c();
  3891. $r .= $DSP->div('itemWrapper').
  3892. $DSP->qdiv('itemWrapper', $DSP->qdiv('defaultBold', $LANG->line('category_parent'))).
  3893. $DSP->input_select_header('parent_id').
  3894. $DSP->input_select_option('0', $LANG->line('none'));
  3895. $this->category_tree('list', $group_id, $parent_id, $sort_order);
  3896. foreach ($this->categories as $val)
  3897. {
  3898. $prefix = (strlen($val['0']) == 1) ? NBS.NBS : NBS;
  3899. $r .= $val;
  3900. }
  3901. $r .= $DSP->input_select_footer().
  3902. $DSP->div_c();
  3903. /** ---------------------------------------
  3904. /** Display custom fields
  3905. /** ---------------------------------------*/
  3906. $field_query = $DB->query("SELECT * FROM exp_category_fields WHERE group_id = '".$DB->escape_str($group_id)."' ORDER BY field_order");
  3907. $data_query = $DB->query("SELECT * FROM exp_category_field_data WHERE cat_id = '".$DB->escape_str($cat_id)."'");
  3908. if ($field_query->num_rows > 0)
  3909. {
  3910. $r .= $DSP->qdiv('publishLine', '');
  3911. foreach ($field_query->result as $row)
  3912. {
  3913. $convert_ascii = ($PREFS->ini('auto_convert_high_ascii') == 'y') ? TRUE : FALSE;
  3914. $r .= $DSP->div('publishRows');
  3915. $field_content = (! isset($data_query->row['field_id_'.$row['field_id']])) ? '' : $data_query->row['field_id_'.$row['field_id']];
  3916. $field_fmt = (! isset($data_query->row['field_ft_'.$row['field_id']])) ? $row['field_default_fmt'] : $data_query->row['field_ft_'.$row['field_id']];
  3917. $text_direction = $row['field_text_direction'];
  3918. $id = $row['field_id'];
  3919. $width = '100%';
  3920. $required = ($row['field_required'] == 'n') ? '' : $DSP->required().NBS;
  3921. $format_sel = '';
  3922. if ($row['field_show_fmt'] == 'y')
  3923. {
  3924. $format_sel = $DSP->div('itemWrapper').$DSP->qspan('xhtmlWrapperLight', $LANG->line('formatting'));
  3925. $format_sel .= $DSP->input_select_header('field_ft_'.$id);
  3926. $format_sel .= $DSP->input_select_option('none', $LANG->line('none'), ($field_fmt == 'none') ? 1 : '');
  3927. // Fetch formatting plugins
  3928. $list = $this->fetch_plugins();
  3929. foreach($list as $val)
  3930. {
  3931. $name = ucwords(str_replace('_', ' ', $val));
  3932. if ($name == 'Br')
  3933. {
  3934. $name = $LANG->line('auto_br');
  3935. }
  3936. elseif ($name == 'Xhtml')
  3937. {
  3938. $name = $LANG->line('xhtml');
  3939. }
  3940. $selected = ($field_fmt == $val) ? 1 : '';
  3941. $format_sel .= $DSP->input_select_option($val, $name, $selected);
  3942. }
  3943. $format_sel .= $DSP->input_select_footer();
  3944. $format_sel .= $DSP->div_c();
  3945. }
  3946. else
  3947. {
  3948. $r .= $DSP->input_hidden('field_ft_'.$id, $field_fmt);
  3949. }
  3950. switch ($row['field_type'])
  3951. {
  3952. case 'textarea' :
  3953. $rows = ( ! isset($row['field_ta_rows'])) ? '10' : $row['field_ta_rows'];
  3954. $r .= $DSP->div('itemWrapper').
  3955. $DSP->qdiv('itemWrapper', $DSP->qdiv('defaultBold', $required.$row['field_label'])).
  3956. $DSP->input_textarea('field_id_'.$id, $field_content,
  3957. $rows, 'textarea', $width, '', $convert_ascii, $text_direction).
  3958. $format_sel.
  3959. $DSP->div_c();
  3960. break;
  3961. case 'text' :
  3962. $r .= $DSP->div('itemWrapper').
  3963. $DSP->qdiv('itemWrapper', $DSP->qdiv('defaultBold', $required.$row['field_label'])).
  3964. $DSP->input_text('field_id_'.$id, $field_content,
  3965. '50', $row['field_maxl'], 'input', $width, '', $convert_ascii, $text_direction).
  3966. $format_sel.
  3967. $DSP->div_c();
  3968. break;
  3969. case 'select' :
  3970. $r .= $DSP->div('itemWrapper').
  3971. $DSP->qdiv('itemWrapper', $DSP->qdiv('defaultBold', $required.$row['field_label']));
  3972. $r .= $DSP->input_select_header('field_id_'.$id);
  3973. foreach (explode("\n", trim($row['field_list_items'])) as $v)
  3974. {
  3975. $v = trim($v);
  3976. $selected = ($v == $field_content) ? 1 : '';
  3977. $v = $REGX->form_prep($v);
  3978. $r .= $DSP->input_select_option($v, $v, $selected, "dir='{$text_direction}'");
  3979. }
  3980. $r .= $DSP->input_select_footer().
  3981. $format_sel.
  3982. $DSP->div_c();
  3983. break;
  3984. }
  3985. $r .= $DSP->div_c();
  3986. }
  3987. }
  3988. // end custom fields
  3989. $r .= $DSP->div_c();
  3990. /** ---------------------------------------
  3991. /** Submit Button
  3992. /** ---------------------------------------*/
  3993. $r .= $DSP->div('itemWrapperTop');
  3994. $r .= ( ! $cat_id) ? $DSP->input_submit($LANG->line('submit')) : $DSP->input_submit($LANG->line('update'));
  3995. $r .= $DSP->div_c();
  3996. $r .= $DSP->form_close();
  3997. $DSP->body = $r;
  3998. }
  3999. /* END */
  4000. /** -----------------------------------------------------------
  4001. /** Category submission handler
  4002. /** -----------------------------------------------------------*/
  4003. // This function receives the category information after
  4004. // being submitted from the form (new or edit) and stores
  4005. // the info in the database.
  4006. //-----------------------------------------------------------
  4007. function update_category()
  4008. {
  4009. global $DB, $DSP, $IN, $REGX, $PREFS, $LANG, $EXT, $FNS;
  4010. if ($IN->GBL('Z') == 1)
  4011. {
  4012. if ( ! $DSP->allowed_group('can_admin_weblogs') AND ! $DSP->allowed_group('can_edit_categories'))
  4013. {
  4014. return $DSP->no_access_message();
  4015. }
  4016. }
  4017. else
  4018. {
  4019. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  4020. {
  4021. return $DSP->no_access_message();
  4022. }
  4023. }
  4024. if (($group_id = $IN->GBL('group_id')) === FALSE OR ! is_numeric($group_id))
  4025. {
  4026. return $DSP->no_access_message();
  4027. }
  4028. $edit = ( ! $IN->GBL('cat_id', 'POST')) ? FALSE : TRUE;
  4029. if ( ! $IN->GBL('cat_name', 'POST'))
  4030. {
  4031. return $this->category_manager($group_id);
  4032. }
  4033. /** ---------------------------------------
  4034. /** Create and validate Category URL Title
  4035. /** ---------------------------------------*/
  4036. if ( ! $IN->GBL('cat_url_title'))
  4037. {
  4038. $_POST['cat_url_title'] = $REGX->create_url_title($_POST['cat_name'], TRUE);
  4039. }
  4040. // Kill all the extraneous characters.
  4041. // We want the URL title to pure alpha text
  4042. $_POST['cat_url_title'] = $REGX->create_url_title($_POST['cat_url_title']);
  4043. // Is the cat_url_title a pure number? If so we show an error.
  4044. if (is_numeric($_POST['cat_url_title']))
  4045. {
  4046. return $DSP->error_message($LANG->line('cat_url_title_is_numeric'));
  4047. }
  4048. /** -------------------------------------
  4049. /** Is the Category URL Title empty? Can't have that
  4050. /** -------------------------------------*/
  4051. if (trim($_POST['cat_url_title']) == '')
  4052. {
  4053. return $DSP->error_message($LANG->line('unable_to_create_cat_url_title'));
  4054. }
  4055. /** ---------------------------------------
  4056. /** Cat URL Title must be unique within the group
  4057. /** ---------------------------------------*/
  4058. $sql = "SELECT COUNT(*) AS count FROM exp_categories
  4059. WHERE cat_url_title = '".$DB->escape_str($_POST['cat_url_title'])."'
  4060. AND group_id = '".$DB->escape_str($group_id)."' ";
  4061. if ($edit === TRUE)
  4062. {
  4063. $sql .= "AND cat_id != '".$DB->escape_str($_POST['cat_id'])."'";
  4064. }
  4065. $query = $DB->query($sql);
  4066. if ($query->row['count'] > 0)
  4067. {
  4068. return $DSP->error_message($LANG->line('duplicate_cat_url_title'));
  4069. }
  4070. /** ---------------------------------------
  4071. /** Finish data prep for insertion
  4072. /** ---------------------------------------*/
  4073. if ($PREFS->ini('auto_convert_high_ascii') == 'y')
  4074. {
  4075. $_POST['cat_name'] = $REGX->ascii_to_entities($_POST['cat_name']);
  4076. }
  4077. $_POST['cat_name'] = str_replace('<', '&lt;', $_POST['cat_name']);
  4078. $_POST['cat_name'] = str_replace('>', '&gt;', $_POST['cat_name']);
  4079. /** ---------------------------------------
  4080. /** Pull out custom field data for later insertion
  4081. /** ---------------------------------------*/
  4082. $fields = array();
  4083. foreach ($_POST as $key => $val)
  4084. {
  4085. if (strpos($key, 'field') !== FALSE)
  4086. {
  4087. $fields[$key] = $val;
  4088. unset($_POST[$key]);
  4089. }
  4090. }
  4091. /** ---------------------------------------
  4092. /** Check for missing required custom fields
  4093. /** ---------------------------------------*/
  4094. $query = $DB->query("SELECT field_id, field_label FROM exp_category_fields WHERE group_id = '".$DB->escape_str($group_id)."' AND field_required = 'y'");
  4095. $missing = array();
  4096. if ($query->num_rows > 0)
  4097. {
  4098. foreach ($query->result as $row)
  4099. {
  4100. if ( ! isset($fields['field_id_'.$row['field_id']]) OR $fields['field_id_'.$row['field_id']] == '')
  4101. {
  4102. $missing[] = $row['field_label'];
  4103. }
  4104. }
  4105. }
  4106. // Are there errors to display?
  4107. if (count($missing) > 0)
  4108. {
  4109. $str = $LANG->line('missing_required_fields').BR.BR;
  4110. foreach ($missing as $msg)
  4111. {
  4112. $str .= $msg.BR;
  4113. }
  4114. return $DSP->error_message($str);
  4115. }
  4116. // -------------------------------------------
  4117. // 'publish_admin_update_category' hook.
  4118. // - New or Update Category script processing
  4119. //
  4120. $edata = $EXT->call_extension('publish_admin_update_category');
  4121. if ($EXT->end_script === TRUE) return;
  4122. //
  4123. // -------------------------------------------
  4124. $_POST['site_id'] = $PREFS->ini('site_id');
  4125. if ($edit == FALSE)
  4126. {
  4127. $sql = $DB->insert_string('exp_categories', $_POST);
  4128. $DB->query($sql);
  4129. $update = FALSE;
  4130. // need this later for custom fields
  4131. $field_cat_id = $DB->insert_id;
  4132. /** ------------------------
  4133. /** Re-order categories
  4134. /** ------------------------*/
  4135. // When a new category is inserted we need to assign it an order.
  4136. // Since the list of categories might have a custom order, all we
  4137. // can really do is position the new category alphabetically.
  4138. // First we'll fetch all the categories alphabetically and assign
  4139. // the position of our new category
  4140. $query = $DB->query("SELECT cat_id, cat_name FROM exp_categories WHERE group_id = '".$DB->escape_str($group_id)."' AND parent_id = '".$DB->escape_str($_POST['parent_id'])."' ORDER BY cat_name asc");
  4141. $position = 0;
  4142. $cat_id = '';
  4143. foreach ($query->result as $row)
  4144. {
  4145. if ($_POST['cat_name'] == $row['cat_name'])
  4146. {
  4147. $cat_id = $row['cat_id'];
  4148. break;
  4149. }
  4150. $position++;
  4151. }
  4152. // Next we'll fetch the list of categories ordered by the custom order
  4153. // and create an array with the category ID numbers
  4154. $query = $DB->query("SELECT cat_id, cat_name FROM exp_categories WHERE group_id = '".$DB->escape_str($group_id)."' AND parent_id = '".$DB->escape_str($_POST['parent_id'])."' AND cat_id != '".$DB->escape_str($cat_id)."' ORDER BY cat_order");
  4155. $cat_array = array();
  4156. foreach ($query->result as $row)
  4157. {
  4158. $cat_array[] = $row['cat_id'];
  4159. }
  4160. // Now we'll splice in our new category to the array.
  4161. // Thus, we now have an array in the proper order, with the new
  4162. // category added in alphabetically
  4163. array_splice($cat_array, $position, 0, $cat_id);
  4164. // Lastly, update the whole list
  4165. $i = 1;
  4166. foreach ($cat_array as $val)
  4167. {
  4168. $DB->query("UPDATE exp_categories SET cat_order = '$i' WHERE cat_id = '$val'");
  4169. $i++;
  4170. }
  4171. }
  4172. else
  4173. {
  4174. if ($_POST['cat_id'] == $_POST['parent_id'])
  4175. {
  4176. $_POST['parent_id'] = 0;
  4177. }
  4178. /** -----------------------------
  4179. /** Check for parent becoming child of its child...oy!
  4180. /** -----------------------------*/
  4181. $query = $DB->query("SELECT parent_id, group_id FROM exp_categories WHERE cat_id = '".$DB->escape_str($IN->GBL('cat_id', 'POST'))."'");
  4182. if ($IN->GBL('parent_id') !== 0 && $query->num_rows > 0 && $query->row['parent_id'] !== $IN->GBL('parent_id'))
  4183. {
  4184. $children = array();
  4185. $cat_array = $this->category_tree('data', $query->row['group_id']);
  4186. foreach($cat_array as $key => $values)
  4187. {
  4188. if ($values['0'] == $IN->GBL('cat_id', 'POST'))
  4189. {
  4190. $children[] = $key;
  4191. }
  4192. }
  4193. if (sizeof($children) > 0)
  4194. {
  4195. if (($key = array_search($IN->GBL('parent_id'), $children)) !== FALSE)
  4196. {
  4197. $DB->query($DB->update_string('exp_categories', array('parent_id' => $query->row['parent_id']), "cat_id = '".$children[$key]."'"));
  4198. }
  4199. /** --------------------------
  4200. /** Find All Descendants
  4201. /** --------------------------*/
  4202. else
  4203. {
  4204. while(sizeof($children) > 0)
  4205. {
  4206. $now = array_shift($children);
  4207. foreach($cat_array as $key => $values)
  4208. {
  4209. if ($values[0] == $now)
  4210. {
  4211. if ($key == $IN->GBL('parent_id'))
  4212. {
  4213. $DB->query($DB->update_string('exp_categories', array('parent_id' => $query->row['parent_id']), "cat_id = '".$key."'"));
  4214. break 2;
  4215. }
  4216. $children[] = $key;
  4217. }
  4218. }
  4219. }
  4220. }
  4221. }
  4222. }
  4223. $sql = $DB->update_string(
  4224. 'exp_categories',
  4225. array(
  4226. 'cat_name' => $IN->GBL('cat_name', 'POST'),
  4227. 'cat_url_title' => $IN->GBL('cat_url_title', 'POST'),
  4228. 'cat_description' => $IN->GBL('cat_description', 'POST'),
  4229. 'cat_image' => $IN->GBL('cat_image', 'POST'),
  4230. 'parent_id' => $IN->GBL('parent_id', 'POST')
  4231. ),
  4232. array(
  4233. 'cat_id' => $IN->GBL('cat_id', 'POST'),
  4234. 'group_id' => $IN->GBL('group_id', 'POST')
  4235. )
  4236. );
  4237. $DB->query($sql);
  4238. $update = TRUE;
  4239. // need this later for custom fields
  4240. $field_cat_id = $IN->GBL('cat_id', 'POST');
  4241. }
  4242. /** ---------------------------------------
  4243. /** Insert / Update Custom Field Data
  4244. /** ---------------------------------------*/
  4245. if ($edit == FALSE)
  4246. {
  4247. $fields['site_id'] = $PREFS->ini('site_id');
  4248. $fields['cat_id'] = $field_cat_id;
  4249. $fields['group_id'] = $group_id;
  4250. $DB->query($DB->insert_string('exp_category_field_data', $fields));
  4251. }
  4252. elseif (! empty($fields))
  4253. {
  4254. $DB->query($DB->update_string('exp_category_field_data', $fields, array('cat_id' => $field_cat_id)));
  4255. }
  4256. $FNS->clear_caching('relationships');
  4257. return $this->category_manager($group_id, $update);
  4258. }
  4259. /* END */
  4260. /** -------------------------------------
  4261. /** Delete category confirm
  4262. /** ------------------------------------*/
  4263. function delete_category_confirm()
  4264. {
  4265. global $DSP, $IN, $DB, $LANG, $SESS;
  4266. if ( ! $DSP->allowed_group('can_admin_weblogs') AND ! $DSP->allowed_group('can_delete_categories') )
  4267. {
  4268. return $DSP->no_access_message();
  4269. }
  4270. if ( ! $cat_id = $IN->GBL('cat_id'))
  4271. {
  4272. return FALSE;
  4273. }
  4274. $query = $DB->query("SELECT cat_name, group_id FROM exp_categories WHERE cat_id = '$cat_id'");
  4275. if ($query->num_rows == 0)
  4276. {
  4277. return FALSE;
  4278. }
  4279. /** ---------------------------------------
  4280. /** Check discrete privileges
  4281. /** ---------------------------------------*/
  4282. if ($IN->GBL('Z') == 1)
  4283. {
  4284. $zquery = $DB->query("SELECT can_delete_categories FROM exp_category_groups WHERE group_id = '".$DB->escape_str($query->row['group_id'])."'");
  4285. if ($zquery->num_rows == 0)
  4286. {
  4287. return FALSE;
  4288. }
  4289. $can_delete = explode('|', rtrim($zquery->row['can_delete_categories'], '|'));
  4290. if ($SESS->userdata['group_id'] != 1 AND ! in_array($SESS->userdata['group_id'], $can_delete))
  4291. {
  4292. return $DSP->no_access_message();
  4293. }
  4294. }
  4295. $DSP->title = $LANG->line('delete_category');
  4296. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  4297. $DSP->crumb_item($DSP->anchor( BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=categories', $LANG->line('category_groups'))).
  4298. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=category_editor'.AMP.'group_id='.$query->row['group_id'], $LANG->line('categories'))).
  4299. $DSP->crumb_item($LANG->line('delete_category'));
  4300. $zurl = ($IN->GBL('Z') == 1) ? AMP.'Z=1' : '';
  4301. $zurl .= ($IN->GBL('cat_group') !== FALSE) ? AMP.'cat_group='.$IN->GBL('cat_group') : '';
  4302. $zurl .= ($IN->GBL('integrated') !== FALSE) ? AMP.'integrated='.$IN->GBL('integrated') : '';
  4303. $DSP->body = $DSP->delete_confirmation(
  4304. array(
  4305. 'url' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=del_category'.AMP.'group_id='.$query->row['group_id'].AMP.'cat_id='.$cat_id.$zurl,
  4306. 'heading' => 'delete_category',
  4307. 'message' => 'delete_category_confirmation',
  4308. 'item' => $query->row['cat_name'],
  4309. 'extra' => '',
  4310. 'hidden' => ''
  4311. )
  4312. );
  4313. }
  4314. /* END */
  4315. /** -----------------------------------------------------------
  4316. /** Delete category
  4317. /** -----------------------------------------------------------*/
  4318. // Deletes a cateogory and removes it from all weblog entries
  4319. //-----------------------------------------------------------
  4320. function delete_category()
  4321. {
  4322. global $DSP, $IN, $DB, $SESS;
  4323. if ( ! $DSP->allowed_group('can_admin_weblogs') AND ! $DSP->allowed_group('can_delete_categories') )
  4324. {
  4325. return $DSP->no_access_message();
  4326. }
  4327. if ( ! $cat_id = $IN->GBL('cat_id'))
  4328. {
  4329. return FALSE;
  4330. }
  4331. if ( ! is_numeric($cat_id))
  4332. {
  4333. return FALSE;
  4334. }
  4335. $query = $DB->query("SELECT group_id FROM exp_categories WHERE cat_id = '".$DB->escape_str($cat_id)."'");
  4336. if ($query->num_rows == 0)
  4337. {
  4338. return FALSE;
  4339. }
  4340. /** ---------------------------------------
  4341. /** Check discrete privileges
  4342. /** ---------------------------------------*/
  4343. if ($IN->GBL('Z') == 1)
  4344. {
  4345. $zquery = $DB->query("SELECT can_delete_categories FROM exp_category_groups WHERE group_id = '".$DB->escape_str($query->row['group_id'])."'");
  4346. if ($zquery->num_rows == 0)
  4347. {
  4348. return FALSE;
  4349. }
  4350. $can_delete = explode('|', rtrim($zquery->row['can_delete_categories'], '|'));
  4351. if ($SESS->userdata['group_id'] != 1 AND ! in_array($SESS->userdata['group_id'], $can_delete))
  4352. {
  4353. return $DSP->no_access_message();
  4354. }
  4355. }
  4356. $group_id = $query->row['group_id'];
  4357. $DB->query("DELETE FROM exp_category_posts WHERE cat_id = '".$DB->escape_str($cat_id)."'");
  4358. $DB->query("UPDATE exp_categories SET parent_id = '0' WHERE parent_id = '".$DB->escape_str($cat_id)."' AND group_id = '".$DB->escape_str($group_id)."'");
  4359. $DB->query("DELETE FROM exp_categories WHERE cat_id = '".$DB->escape_str($cat_id)."' AND group_id = '".$DB->escape_str($group_id)."'");
  4360. $DB->query("DELETE FROM exp_category_field_data WHERE cat_id = '".$DB->escape_str($cat_id)."'");
  4361. $this->category_manager($group_id);
  4362. }
  4363. /* END */
  4364. //=====================================================================
  4365. // STATUS ADMINISTRATION FUNCTIONS
  4366. //=====================================================================
  4367. /** -----------------------------------------------------------
  4368. /** Status overview page
  4369. /** -----------------------------------------------------------*/
  4370. // This function show the list of current status groups.
  4371. // It is accessed by clicking "Custom entry statuses"
  4372. // in the "admin" tab
  4373. //-----------------------------------------------------------
  4374. function status_overview($message = '')
  4375. {
  4376. global $LANG, $DSP, $DB, $PREFS;
  4377. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  4378. {
  4379. return $DSP->no_access_message();
  4380. }
  4381. $DSP->title = $LANG->line('status_groups');
  4382. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  4383. $DSP->crumb_item($LANG->line('status_groups'));
  4384. $DSP->right_crumb($LANG->line('create_new_status_group'), BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=status_group_editor');
  4385. // Fetch category groups
  4386. $sql = "SELECT exp_status_groups.group_id, exp_status_groups.group_name,
  4387. COUNT(exp_statuses.group_id) as count
  4388. FROM exp_status_groups
  4389. LEFT JOIN exp_statuses ON (exp_status_groups.group_id = exp_statuses.group_id)
  4390. WHERE exp_status_groups.site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'
  4391. GROUP BY exp_status_groups.group_id
  4392. ORDER BY exp_status_groups.group_name";
  4393. $query = $DB->query($sql);
  4394. if ($query->num_rows == 0)
  4395. {
  4396. $DSP->body = $DSP->qdiv('tableHeading', $LANG->line('status_groups'));
  4397. if ($message != '')
  4398. {
  4399. $DSP->body .= $DSP->qdiv('box', stripslashes($message));
  4400. }
  4401. $DSP->body .= $DSP->div('box');
  4402. $DSP->body .= $DSP->qdiv('itemWrapper', $DSP->heading($LANG->line('no_status_group_message'), 5));
  4403. $DSP->body .= $DSP->qdiv('itemWrapper', $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=status_group_editor', $LANG->line('create_new_status_group')));
  4404. $DSP->body .= $DSP->div_c();
  4405. return;
  4406. }
  4407. $r = '';
  4408. if ($message != '')
  4409. {
  4410. $r .= $DSP->qdiv('box', stripslashes($message));
  4411. }
  4412. $r .= $DSP->table('tableBorder', '0', '', '100%').
  4413. $DSP->tr().
  4414. $DSP->td('tableHeading', '', '4').
  4415. $LANG->line('status_groups').
  4416. $DSP->td_c().
  4417. $DSP->tr_c();
  4418. $i = 0;
  4419. foreach($query->result as $row)
  4420. {
  4421. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  4422. $r .= $DSP->tr();
  4423. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $row['group_name']));
  4424. $r .= $DSP->table_qcell($style,
  4425. '('.$row['count'].')'.$DSP->nbs(2).
  4426. $DSP->anchor(
  4427. BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=status_editor'.AMP.'group_id='.$row['group_id'],
  4428. $LANG->line('add_edit_statuses')
  4429. ));
  4430. $r .= $DSP->table_qcell($style,
  4431. $DSP->anchor(
  4432. BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=status_group_editor'.AMP.'group_id='.$row['group_id'],
  4433. $LANG->line('edit_status_group_name')
  4434. ));
  4435. $r .= $DSP->table_qcell($style,
  4436. $DSP->anchor(
  4437. BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=status_group_del_conf'.AMP.'group_id='.$row['group_id'],
  4438. $LANG->line('delete_status_group')
  4439. ));
  4440. $r .= $DSP->tr_c();
  4441. }
  4442. $r .= $DSP->table_c();
  4443. $DSP->body = $r;
  4444. }
  4445. /* END */
  4446. /** -----------------------------------------------------------
  4447. /** New/edit status group form
  4448. /** -----------------------------------------------------------*/
  4449. // This function lets you create or edit a status group
  4450. //-----------------------------------------------------------
  4451. function edit_status_group_form()
  4452. {
  4453. global $DSP, $IN, $DB, $REGX, $LANG;
  4454. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  4455. {
  4456. return $DSP->no_access_message();
  4457. }
  4458. // Set default values
  4459. $edit = FALSE;
  4460. $group_id = '';
  4461. $group_name = '';
  4462. // If we have the group_id variable it's an edit request, so fetch the status data
  4463. if ($group_id = $IN->GBL('group_id'))
  4464. {
  4465. $edit = TRUE;
  4466. if ( ! is_numeric($group_id))
  4467. {
  4468. return FALSE;
  4469. }
  4470. $query = $DB->query("SELECT * FROM exp_status_groups WHERE group_id = '".$DB->escape_str($group_id)."'");
  4471. foreach ($query->row as $key => $val)
  4472. {
  4473. $$key = $val;
  4474. }
  4475. }
  4476. if ($edit == FALSE)
  4477. $title = $LANG->line('create_new_status_group');
  4478. else
  4479. $title = $LANG->line('edit_status_group');
  4480. // Build our output
  4481. $r = $DSP->form_open(array('action' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=update_status_group'));
  4482. if ($edit == TRUE)
  4483. $r .= $DSP->input_hidden('group_id', $group_id);
  4484. $r .= $DSP->qdiv('tableHeading', $title);
  4485. $r .= $DSP->div('box').
  4486. $DSP->qdiv('itemWrapper', $DSP->qdiv('defaultBold', $LANG->line('name_of_status_group', 'group_name'))).
  4487. $DSP->qdiv('itemWrapper', $DSP->input_text('group_name', $group_name, '20', '50', 'input', '260px'));
  4488. $r .= $DSP->div_c();
  4489. $r .= $DSP->div('itemWrapperTop');
  4490. if ($edit == FALSE)
  4491. $r .= $DSP->input_submit($LANG->line('submit'));
  4492. else
  4493. $r .= $DSP->input_submit($LANG->line('update'));
  4494. $r .= $DSP->div_c();
  4495. $r .= $DSP->form_close();
  4496. $DSP->title = $title;
  4497. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  4498. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=statuses', $LANG->line('status_groups'))).
  4499. $DSP->crumb_item($title);
  4500. $DSP->body = $r;
  4501. }
  4502. /* END */
  4503. /** -----------------------------------------------------------
  4504. /** Status group submission handler
  4505. /** -----------------------------------------------------------*/
  4506. // This function receives the submitted status group data
  4507. // and puts it in the database
  4508. //-----------------------------------------------------------
  4509. function update_status_group()
  4510. {
  4511. global $DSP, $IN, $DB, $LOG, $LANG, $PREFS;
  4512. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  4513. {
  4514. return $DSP->no_access_message();
  4515. }
  4516. // If the $group_id variable is present we are editing an
  4517. // existing group, otherwise we are creating a new one
  4518. $edit = (isset($_POST['group_id'])) ? TRUE : FALSE;
  4519. if ($_POST['group_name'] == '')
  4520. {
  4521. return $this->edit_status_group_form();
  4522. }
  4523. if ( ! preg_match("#^[a-zA-Z0-9_\-/\s]+$#i", $_POST['group_name']))
  4524. {
  4525. return $DSP->error_message($LANG->line('illegal_characters'));
  4526. }
  4527. // Is the group name taken?
  4528. $sql = "SELECT count(*) as count FROM exp_status_groups WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND group_name = '".$DB->escape_str($_POST['group_name'])."'";
  4529. if ($edit == TRUE)
  4530. {
  4531. $sql .= " AND group_id != '".$DB->escape_str($_POST['group_id'])."'";
  4532. }
  4533. $query = $DB->query($sql);
  4534. if ($query->row['count'] > 0)
  4535. {
  4536. return $DSP->error_message($LANG->line('taken_status_group_name'));
  4537. }
  4538. // Construct the query based on whether we are updating or inserting
  4539. if ($edit == FALSE)
  4540. {
  4541. unset($_POST['group_id']);
  4542. $_POST['site_id'] = $PREFS->ini('site_id');
  4543. $DB->query($DB->insert_string('exp_status_groups', $_POST));
  4544. $group_id = $DB->insert_id;
  4545. $DB->query("INSERT INTO exp_statuses (status_id, site_id, group_id, status, status_order, highlight) VALUES ('', '".$DB->escape_str($PREFS->ini('site_id'))."', '$group_id', 'open', '1', '$this->status_color_open')");
  4546. $DB->query("INSERT INTO exp_statuses (status_id, site_id, group_id, status, status_order, highlight) VALUES ('', '".$DB->escape_str($PREFS->ini('site_id'))."', '$group_id', 'closed', '2', '$this->status_color_closed')");
  4547. $success_msg = $LANG->line('status_group_created');
  4548. $crumb = $DSP->crumb_item($LANG->line('new_status'));
  4549. $LOG->log_action($LANG->line('status_group_created').$DSP->nbs(2).$_POST['group_name']);
  4550. }
  4551. else
  4552. {
  4553. $DB->query($DB->update_string('exp_status_groups', $_POST, 'group_id='.$DB->escape_str($_POST['group_id'])));
  4554. $success_msg = $LANG->line('status_group_updated');
  4555. $crumb = $DSP->crumb_item($LANG->line('update'));
  4556. }
  4557. $message = $DSP->qdiv('itemWrapper', $DSP->qspan('success', $success_msg).NBS.NBS.'<b>'.$_POST['group_name'].'</b>');
  4558. if ($edit == FALSE)
  4559. {
  4560. $query = $DB->query("SELECT weblog_id from exp_weblogs WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND is_user_blog = 'n'");
  4561. if ($query->num_rows > 0)
  4562. {
  4563. $message .= $DSP->div('itemWrapper').$DSP->span('alert').$LANG->line('assign_group_to_weblog').$DSP->span_c().$DSP->nbs(2);
  4564. if ($query->num_rows == 1)
  4565. {
  4566. $link = 'C=admin'.AMP.'M=blog_admin'.AMP.'P=group_prefs'.AMP.'weblog_id='.$query->row['weblog_id'];
  4567. }
  4568. else
  4569. {
  4570. $link = 'C=admin'.AMP.'M=blog_admin'.AMP.'P=blog_list';
  4571. }
  4572. $message .= $DSP->anchor(BASE.AMP.$link, $LANG->line('click_to_assign_group')).$DSP->div_c();
  4573. }
  4574. }
  4575. return $this->status_overview($message);
  4576. }
  4577. /* END */
  4578. /** -----------------------------------------------------------
  4579. /** Delete status group confirm
  4580. /** -----------------------------------------------------------*/
  4581. // Warning message shown when you try to delete a status group
  4582. //-----------------------------------------------------------
  4583. function delete_status_group_conf()
  4584. {
  4585. global $DSP, $IN, $DB, $LANG;
  4586. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  4587. {
  4588. return $DSP->no_access_message();
  4589. }
  4590. if (($group_id = $IN->GBL('group_id')) === FALSE OR ! is_numeric($group_id))
  4591. {
  4592. return FALSE;
  4593. }
  4594. $query = $DB->query("SELECT group_name FROM exp_status_groups WHERE group_id = '".$DB->escape_str($group_id)."'");
  4595. $DSP->title = $LANG->line('delete_group');
  4596. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  4597. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=statuses', $LANG->line('status_groups'))).
  4598. $DSP->crumb_item($LANG->line('delete_group'));
  4599. $DSP->body = $DSP->delete_confirmation(
  4600. array(
  4601. 'url' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=delete_status_group'.AMP.'group_id='.$group_id,
  4602. 'heading' => 'delete_group',
  4603. 'message' => 'delete_status_group_confirmation',
  4604. 'item' => $query->row['group_name'],
  4605. 'extra' => '',
  4606. 'hidden' => array('group_id' => $group_id)
  4607. )
  4608. );
  4609. }
  4610. /* END */
  4611. /** -----------------------------------------------------------
  4612. /** Delete status group
  4613. /** -----------------------------------------------------------*/
  4614. // This function nukes the status group and associated statuses
  4615. //-----------------------------------------------------------
  4616. function delete_status_group()
  4617. {
  4618. global $DSP, $IN, $DB, $LOG, $LANG;
  4619. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  4620. {
  4621. return $DSP->no_access_message();
  4622. }
  4623. if (($group_id = $IN->GBL('group_id')) === FALSE OR ! is_numeric($group_id))
  4624. {
  4625. return FALSE;
  4626. }
  4627. $query = $DB->query("SELECT group_name FROM exp_status_groups WHERE group_id = '".$DB->escape_str($group_id)."'");
  4628. $name = $query->row['group_name'];
  4629. $DB->query("DELETE FROM exp_status_groups WHERE group_id = '".$DB->escape_str($group_id)."'");
  4630. $DB->query("DELETE FROM exp_statuses WHERE group_id = '".$DB->escape_str($group_id)."'");
  4631. $LOG->log_action($LANG->line('status_group_deleted').$DSP->nbs(2).$name);
  4632. $message = $DSP->qspan('success', $LANG->line('status_group_deleted')).$DSP->nbs(2).'<b>'.$name.'</b>';
  4633. return $this->status_overview($message);
  4634. }
  4635. /* END */
  4636. /** -----------------------------------------------------------
  4637. /** Status manager
  4638. /** -----------------------------------------------------------*/
  4639. // This function lets you create/edit statuses
  4640. //-----------------------------------------------------------
  4641. function status_manager($group_id = '', $update = FALSE)
  4642. {
  4643. global $DSP, $IN, $DB, $SESS, $LANG, $PREFS;
  4644. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  4645. {
  4646. return $DSP->no_access_message();
  4647. }
  4648. if ($group_id == '')
  4649. {
  4650. if (($group_id = $IN->GBL('group_id')) === FALSE OR ! is_numeric($group_id))
  4651. {
  4652. return FALSE;
  4653. }
  4654. }
  4655. elseif ( ! is_numeric($group_id))
  4656. {
  4657. return FALSE;
  4658. }
  4659. $i = 0;
  4660. ;
  4661. $r = '';
  4662. if ($update == TRUE)
  4663. {
  4664. if (isset($_GET['group_id']))
  4665. {
  4666. $r .= $DSP->qdiv('box', $DSP->qdiv('success', $LANG->line('status_created')));
  4667. }
  4668. else
  4669. {
  4670. $r .= $DSP->qdiv('box', $DSP->qdiv('success', $LANG->line('status_updated')));
  4671. }
  4672. }
  4673. $r .= $DSP->table('', '0', '10', '100%').
  4674. $DSP->tr().
  4675. $DSP->td('', '55%', '', '', 'top');
  4676. $query = $DB->query("SELECT group_name FROM exp_status_groups WHERE group_id = '".$DB->escape_str($group_id)."'");
  4677. $r .= $DSP->table('tableBorder', '0', '10', '100%').
  4678. $DSP->tr().
  4679. $DSP->td('tableHeading', '', '3').
  4680. $DSP->qspan('altLink', $LANG->line('status_group').':').$DSP->nbs(2).$query->row['group_name'].
  4681. $DSP->td_c().
  4682. $DSP->tr_c();
  4683. $query = $DB->query("SELECT status_id, status FROM exp_statuses WHERE group_id = '".$DB->escape_str($group_id)."' ORDER BY status_order");
  4684. $total = $query->num_rows + 1;
  4685. if ($query->num_rows > 0)
  4686. {
  4687. foreach ($query->result as $row)
  4688. {
  4689. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  4690. $del = ($row['status'] != 'open' AND $row['status'] != 'closed') ? $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=del_status_conf'.AMP.'status_id='.$row['status_id'], $LANG->line('delete')) : '--';
  4691. $status_name = ($row['status'] == 'open' OR $row['status'] == 'closed') ? $LANG->line($row['status']) : $row['status'];
  4692. $r .= $DSP->tr().
  4693. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $status_name)).
  4694. $DSP->table_qcell($style, $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=edit_status'.AMP.'status_id='.$row['status_id'], $LANG->line('edit'))).
  4695. $DSP->table_qcell($style, $del).
  4696. $DSP->tr_c();
  4697. }
  4698. }
  4699. $r .= $DSP->table_c();
  4700. $r .= $DSP->qdiv('itemWrapper', $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=edit_status_order'.AMP.'group_id='.$group_id, $LANG->line('change_status_order')));
  4701. $r .= $DSP->td_c().
  4702. $DSP->td('rightCel', '45%', '', '', 'top');
  4703. // Build the right side output
  4704. $r .= $DSP->form_open(array('action' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=update_status'.AMP.'group_id='.$group_id)).
  4705. $DSP->input_hidden('group_id', $group_id);
  4706. $r .= $DSP->qdiv('tableHeading', $LANG->line('create_new_status'));
  4707. $r .= $DSP->div('box');
  4708. $r .= $DSP->qdiv('', $DSP->qdiv('itemWrapper', $LANG->line('status_name', 'status')).$DSP->input_text('status', '', '30', '60', 'input', '260px'));
  4709. $r .= $DSP->qdiv('', $DSP->qdiv('itemWrapper', $LANG->line('status_order', 'status_order')).$DSP->input_text('status_order', $total, '20', '3', 'input', '50px'));
  4710. $r .= $DSP->qdiv('', $DSP->qdiv('itemWrapper', $LANG->line('highlight', 'highlight')).$DSP->input_text('highlight', '', '20', '30', 'input', '120px'));
  4711. $r .= $DSP->div_c();
  4712. if (USER_BLOG == FALSE AND $SESS->userdata['group_id'] == 1)
  4713. {
  4714. $query = $DB->query("SELECT group_id, group_title
  4715. FROM exp_member_groups
  4716. WHERE group_id != '1'
  4717. AND group_id != '2'
  4718. AND can_access_cp = 'y'
  4719. AND can_access_publish = 'y'
  4720. AND site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'
  4721. ORDER BY group_title");
  4722. $table_end = TRUE;
  4723. if ($query->num_rows == 0)
  4724. {
  4725. $table_end = FALSE;
  4726. }
  4727. else
  4728. {
  4729. $r .= $DSP->qdiv('itemWrapperTop', $DSP->heading($LANG->line('restrict_status_to_group'), 5));
  4730. $r .= $DSP->table('tableBorder', '0', '', '100%').
  4731. $DSP->tr().
  4732. $DSP->td('tableHeading', '', '').
  4733. $LANG->line('member_group').
  4734. $DSP->td_c().
  4735. $DSP->td('tableHeading', '', '').
  4736. $LANG->line('can_edit_status').
  4737. $DSP->td_c().
  4738. $DSP->tr_c();
  4739. $i = 0;
  4740. $group = array();
  4741. foreach ($query->result as $row)
  4742. {
  4743. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  4744. $r .= $DSP->tr().
  4745. $DSP->td($style, '50%').
  4746. $row['group_title'].
  4747. $DSP->td_c().
  4748. $DSP->td($style, '50%');
  4749. $selected = ( ! isset($group[$row['group_id']])) ? 1 : '';
  4750. $r .= $LANG->line('yes').NBS.
  4751. $DSP->input_radio('access_'.$row['group_id'], 'y', $selected).$DSP->nbs(3);
  4752. $selected = (isset($group[$row['group_id']])) ? 1 : '';
  4753. $r .= $LANG->line('no').NBS.
  4754. $DSP->input_radio('access_'.$row['group_id'], 'n', $selected).$DSP->nbs(3);
  4755. $r .= $DSP->td_c()
  4756. .$DSP->tr_c();
  4757. }
  4758. }
  4759. }
  4760. if ($table_end == TRUE)
  4761. $r .= $DSP->table_c();
  4762. $r .= $DSP->qdiv('itemWrapperTop', $DSP->input_submit($LANG->line('submit')));
  4763. $r .= $DSP->form_close();
  4764. $r .= $DSP->td_c().
  4765. $DSP->tr_c().
  4766. $DSP->table_c();
  4767. $DSP->title = $LANG->line('statuses');
  4768. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  4769. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=statuses', $LANG->line('status_groups'))).
  4770. $DSP->crumb_item($LANG->line('statuses'));
  4771. $DSP->body = $r;
  4772. }
  4773. /* END */
  4774. /** -----------------------------------------------------------
  4775. /** Status submission handler
  4776. /** -----------------------------------------------------------*/
  4777. // This function recieves the submitted status data and
  4778. // inserts it in the database.
  4779. //-----------------------------------------------------------
  4780. function update_status()
  4781. {
  4782. global $DB, $DSP, $LANG, $IN, $PREFS;
  4783. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  4784. {
  4785. return $DSP->no_access_message();
  4786. }
  4787. $edit = ( ! $IN->GBL('status_id', 'POST')) ? FALSE : TRUE;
  4788. if ( ! $IN->GBL('status', 'POST'))
  4789. {
  4790. return $this->status_manager($IN->GBL('group_id', 'POST'));
  4791. }
  4792. if ( ! preg_match( "#^([-a-z0-9_\+ ])+$#i", $IN->GBL('status', 'POST')))
  4793. {
  4794. return $DSP->error_message($LANG->line('invalid_status_name'));
  4795. }
  4796. $data = array(
  4797. 'status' => $IN->GBL('status', 'POST'),
  4798. 'status_order' => (is_numeric($IN->GBL('status_order', 'POST'))) ? $IN->GBL('status_order', 'POST') : 0,
  4799. 'highlight' => $IN->GBL('highlight', 'POST')
  4800. );
  4801. if ($edit == FALSE)
  4802. {
  4803. $query = $DB->query("SELECT count(*) AS count FROM exp_statuses WHERE status = '".$DB->escape_str($_POST['status'])."' AND group_id = '".$DB->escape_str($_POST['group_id'])."'");
  4804. if ($query->row['count'] > 0)
  4805. {
  4806. return $DSP->error_message($LANG->line('duplicate_status_name'));
  4807. }
  4808. $data['group_id'] = $_POST['group_id'];
  4809. $data['site_id'] = $PREFS->ini('site_id');
  4810. $sql = $DB->insert_string('exp_statuses', $data);
  4811. $DB->query($sql);
  4812. $status_id = $DB->insert_id;
  4813. }
  4814. else
  4815. {
  4816. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_statuses WHERE status = '".$DB->escape_str($_POST['status'])."' AND group_id = '".$DB->escape_str($_POST['group_id'])."' AND status_id != '".$DB->escape_str($_POST['status_id'])."'");
  4817. if ($query->row['count'] > 0)
  4818. {
  4819. return $DSP->error_message($LANG->line('duplicate_status_name'));
  4820. }
  4821. $status_id = $IN->GBL('status_id');
  4822. $sql = $DB->update_string(
  4823. 'exp_statuses',
  4824. $data,
  4825. array(
  4826. 'status_id' => $status_id,
  4827. 'group_id' => $IN->GBL('group_id', 'POST')
  4828. )
  4829. );
  4830. $DB->query($sql);
  4831. $DB->query("DELETE FROM exp_status_no_access WHERE status_id = '$status_id'");
  4832. // If the status name has changed, we need to update weblog entries with the new status.
  4833. if ($_POST['old_status'] != $_POST['status'])
  4834. {
  4835. $query = $DB->query("SELECT weblog_id FROM exp_weblogs WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND status_group = '".$DB->escape_str($_POST['group_id'])."'");
  4836. if ($query->num_rows > 0)
  4837. {
  4838. foreach ($query->result as $row)
  4839. {
  4840. $DB->query("UPDATE exp_weblog_titles SET status = '".$DB->escape_str($_POST['status'])."'
  4841. WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'
  4842. AND status = '".$DB->escape_str($_POST['old_status'])."'
  4843. AND weblog_id = '".$row['weblog_id']."'");
  4844. }
  4845. }
  4846. }
  4847. }
  4848. // Set access privs
  4849. foreach ($_POST as $key => $val)
  4850. {
  4851. if (substr($key, 0, 7) == 'access_' AND $val == 'n')
  4852. {
  4853. $DB->query("INSERT INTO exp_status_no_access (status_id, member_group) VALUES ('$status_id', '".substr($key, 7)."')");
  4854. }
  4855. }
  4856. return $this->status_manager($IN->GBL('group_id', 'POST'), TRUE);
  4857. }
  4858. /* END */
  4859. /** -------------------------------------
  4860. /** Edit status form
  4861. /** -------------------------------------*/
  4862. function edit_status_form()
  4863. {
  4864. global $DSP, $IN, $DB, $REGX, $SESS, $LANG, $PREFS;
  4865. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  4866. {
  4867. return $DSP->no_access_message();
  4868. }
  4869. if (($status_id = $IN->GBL('status_id')) === FALSE OR ! is_numeric($status_id))
  4870. {
  4871. return FALSE;
  4872. }
  4873. $query = $DB->query("SELECT * FROM exp_statuses WHERE status_id = '$status_id'");
  4874. $group_id = $query->row['group_id'];
  4875. $status = $query->row['status'];
  4876. $status_order = $query->row['status_order'];
  4877. $color = $query->row['highlight'];
  4878. $status_id = $query->row['status_id'];
  4879. // Build our output
  4880. $r = $DSP->form_open(array('action' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=update_status')).
  4881. $DSP->input_hidden('status_id', $status_id).
  4882. $DSP->input_hidden('old_status', $status).
  4883. $DSP->input_hidden('group_id', $group_id);
  4884. $r .= $DSP->qdiv('tableHeading', $LANG->line('edit_status'));
  4885. $r .= $DSP->div('box');
  4886. if ($status == 'open' OR $status == 'closed')
  4887. {
  4888. $r .= $DSP->input_hidden('status', $status);
  4889. $r .= $DSP->qdiv('itemWrapper', $DSP->qspan('defaultBold', $LANG->line('status_name', 'status').':').NBS.$DSP->qspan('highlight_alt_bold', $LANG->line($status)));
  4890. }
  4891. else
  4892. {
  4893. $r .= $DSP->qdiv('', $DSP->qdiv('itemWrapper', $LANG->line('status_name', 'status')).$DSP->input_text('status', $status, '30', '60', 'input', '260px'));
  4894. }
  4895. $r .= $DSP->qdiv('', $DSP->qdiv('itemWrapper', $LANG->line('status_order', 'status_order')).$DSP->input_text('status_order', $status_order, '20', '3', 'input', '50px'));
  4896. $r .= $DSP->qdiv('', $DSP->qdiv('itemWrapper', $LANG->line('highlight', 'highlight')).$DSP->input_text('highlight', $color, '30', '30', 'input', '120px'));
  4897. $r .= $DSP->div_c();
  4898. if (USER_BLOG == FALSE AND $SESS->userdata['group_id'] == 1)
  4899. {
  4900. $query = $DB->query("SELECT group_id, group_title
  4901. FROM exp_member_groups
  4902. WHERE group_id NOT IN (1,2,3,4)
  4903. AND site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'
  4904. ORDER BY group_title");
  4905. $table_end = TRUE;
  4906. if ($query->num_rows == 0)
  4907. {
  4908. $table_end = FALSE;
  4909. }
  4910. else
  4911. {
  4912. $r .= $DSP->qdiv('itemWrapperTop', $DSP->heading($LANG->line('restrict_status_to_group'), 5));
  4913. $r .= $DSP->table('tableBorder', '0', '', '100%').
  4914. $DSP->tr().
  4915. $DSP->td('tableHeadingAlt', '', '').
  4916. $LANG->line('member_group').
  4917. $DSP->td_c().
  4918. $DSP->td('tableHeadingAlt', '', '').
  4919. $LANG->line('can_edit_status').
  4920. $DSP->td_c().
  4921. $DSP->tr_c();
  4922. $i = 0;
  4923. $group = array();
  4924. $result = $DB->query("SELECT member_group FROM exp_status_no_access WHERE status_id = '$status_id'");
  4925. if ($result->num_rows != 0)
  4926. {
  4927. foreach($result->result as $row)
  4928. {
  4929. $group[$row['member_group']] = TRUE;
  4930. }
  4931. }
  4932. foreach ($query->result as $row)
  4933. {
  4934. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  4935. $r .= $DSP->tr().
  4936. $DSP->td($style, '50%').
  4937. $row['group_title'].
  4938. $DSP->td_c().
  4939. $DSP->td($style, '50%');
  4940. $selected = ( ! isset($group[$row['group_id']])) ? 1 : '';
  4941. $r .= $LANG->line('yes').NBS.
  4942. $DSP->input_radio('access_'.$row['group_id'], 'y', $selected).$DSP->nbs(3);
  4943. $selected = (isset($group[$row['group_id']])) ? 1 : '';
  4944. $r .= $LANG->line('no').NBS.
  4945. $DSP->input_radio('access_'.$row['group_id'], 'n', $selected).$DSP->nbs(3);
  4946. $r .= $DSP->td_c()
  4947. .$DSP->tr_c();
  4948. }
  4949. }
  4950. }
  4951. if ($table_end == TRUE)
  4952. $r .= $DSP->table_c();
  4953. $r .= $DSP->qdiv('itemWrapperTop', $DSP->input_submit($LANG->line('update')));
  4954. $r .= $DSP->form_close();
  4955. $DSP->title = $LANG->line('edit_status');
  4956. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  4957. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=statuses', $LANG->line('status_groups'))).
  4958. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=status_editor'.AMP.'group_id='.$group_id, $LANG->line('statuses'))).
  4959. $DSP->crumb_item($LANG->line('edit_status'));
  4960. $DSP->body = $r;
  4961. }
  4962. /* END */
  4963. /** -------------------------------------------
  4964. /** Delete status confirm
  4965. /** -------------------------------------------*/
  4966. function delete_status_confirm()
  4967. {
  4968. global $DSP, $IN, $DB, $LANG;
  4969. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  4970. {
  4971. return $DSP->no_access_message();
  4972. }
  4973. if (($status_id = $IN->GBL('status_id')) === FALSE OR ! is_numeric($status_id))
  4974. {
  4975. return FALSE;
  4976. }
  4977. $query = $DB->query("SELECT status, group_id FROM exp_statuses WHERE status_id = '$status_id'");
  4978. $DSP->title = $LANG->line('delete_status');
  4979. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  4980. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=status_editor'.AMP.'group_id='.$query->row['group_id'], $LANG->line('status_groups'))).
  4981. $DSP->crumb_item($LANG->line('delete_status'));
  4982. $DSP->body = $DSP->delete_confirmation(
  4983. array(
  4984. 'url' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=del_status'.AMP.'status_id='.$status_id,
  4985. 'heading' => 'delete_status',
  4986. 'message' => 'delete_status_confirmation',
  4987. 'item' => $query->row['status'],
  4988. 'extra' => '',
  4989. 'hidden' => ''
  4990. )
  4991. );
  4992. }
  4993. /* END */
  4994. /** -------------------------------------------
  4995. /** Delete status
  4996. /** -------------------------------------------*/
  4997. function delete_status()
  4998. {
  4999. global $DSP, $IN, $DB, $PREFS;
  5000. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  5001. {
  5002. return $DSP->no_access_message();
  5003. }
  5004. if (($status_id = $IN->GBL('status_id')) === FALSE OR ! is_numeric($status_id))
  5005. {
  5006. return FALSE;
  5007. }
  5008. $query = $DB->query("SELECT status, group_id FROM exp_statuses WHERE status_id = '$status_id'");
  5009. $group_id = $query->row['group_id'];
  5010. $status = $query->row['status'];
  5011. $query = $DB->query("SELECT weblog_id FROM exp_weblogs WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND status_group = '$group_id'");
  5012. if ($query->num_rows > 0)
  5013. {
  5014. $DB->query("UPDATE exp_weblog_titles SET status = 'closed' WHERE status = '$status' AND weblog_id = '".$DB->escape_str($query->row['weblog_id'])."'");
  5015. }
  5016. if ($status != 'open' AND $status != 'closed')
  5017. {
  5018. $DB->query("DELETE FROM exp_statuses WHERE status_id = '$status_id' AND site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND group_id = '".$DB->escape_str($group_id)."'");
  5019. }
  5020. $this->status_manager($group_id);
  5021. }
  5022. /* END */
  5023. /** -------------------------------------------
  5024. /** Edit status order
  5025. /** -------------------------------------------*/
  5026. function edit_status_order()
  5027. {
  5028. global $DSP, $IN, $DB, $LANG;
  5029. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  5030. {
  5031. return $DSP->no_access_message();
  5032. }
  5033. if (($group_id = $IN->GBL('group_id')) === FALSE OR ! is_numeric($group_id))
  5034. {
  5035. return FALSE;
  5036. }
  5037. $query = $DB->query("SELECT status, status_id, status_order FROM exp_statuses WHERE group_id = '".$DB->escape_str($group_id)."' ORDER BY status_order");
  5038. if ($query->num_rows == 0)
  5039. {
  5040. return FALSE;
  5041. }
  5042. $r = $DSP->form_open(array('action' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=update_status_order'));
  5043. $r .= $DSP->input_hidden('group_id', $group_id);
  5044. $r .= $DSP->table('tableBorder', '0', '10', '100%').
  5045. $DSP->tr().
  5046. $DSP->td('tableHeading', '', '2').
  5047. $LANG->line('change_status_order').
  5048. $DSP->td_c().
  5049. $DSP->tr_c();
  5050. foreach ($query->result as $row)
  5051. {
  5052. $status_name = ($row['status'] == 'open' OR $row['status'] == 'closed') ? $LANG->line($row['status']) : $row['status'];
  5053. $r .= $DSP->tr();
  5054. $r .= $DSP->table_qcell('tableCellOne', $status_name);
  5055. $r .= $DSP->table_qcell('tableCellOne', $DSP->input_text($row['status_id'], $row['status_order'], '4', '3', 'input', '30px'));
  5056. $r .= $DSP->tr_c();
  5057. }
  5058. $r .= $DSP->table_c();
  5059. $r .= $DSP->qdiv('itemWrapper', $DSP->input_submit($LANG->line('update')));
  5060. $r .= $DSP->form_close();
  5061. $DSP->title = $LANG->line('change_status_order');
  5062. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  5063. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=statuses', $LANG->line('status_groups'))).
  5064. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=status_editor'.AMP.'group_id='.$group_id, $LANG->line('statuses'))).
  5065. $DSP->crumb_item($LANG->line('change_status_order'));
  5066. $DSP->body = $r;
  5067. }
  5068. /* END */
  5069. /** ---------------------------------------
  5070. /** Update status order
  5071. /** ---------------------------------------*/
  5072. function update_status_order()
  5073. {
  5074. global $DSP, $IN, $DB, $LANG;
  5075. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  5076. {
  5077. return $DSP->no_access_message();
  5078. }
  5079. if ( ! $group_id = $IN->GBL('group_id', 'POST'))
  5080. {
  5081. return FALSE;
  5082. }
  5083. unset($_POST['group_id']);
  5084. foreach ($_POST as $key => $val)
  5085. {
  5086. $DB->query("UPDATE exp_statuses SET status_order = '$val' WHERE status_id = '$key'");
  5087. }
  5088. return $this->status_manager($group_id);
  5089. }
  5090. /* END */
  5091. //=====================================================================
  5092. // CUSTOM FIELD FUNCTIONS
  5093. //=====================================================================
  5094. /** -----------------------------------------------------------
  5095. /** Custom field overview page
  5096. /** -----------------------------------------------------------*/
  5097. // This function show the "Custom weblog fields" page,
  5098. // accessed via the "admin" tab
  5099. //-----------------------------------------------------------
  5100. function field_overview($message = '')
  5101. {
  5102. global $LANG, $DSP, $DB, $PREFS;
  5103. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  5104. {
  5105. return $DSP->no_access_message();
  5106. }
  5107. // Fetch field groups
  5108. $sql = "SELECT exp_field_groups.group_id, exp_field_groups.group_name,
  5109. COUNT(exp_weblog_fields.group_id) as count
  5110. FROM exp_field_groups
  5111. LEFT JOIN exp_weblog_fields ON (exp_field_groups.group_id = exp_weblog_fields.group_id)
  5112. WHERE exp_field_groups.site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'
  5113. GROUP BY exp_field_groups.group_id
  5114. ORDER BY exp_field_groups.group_name";
  5115. $query = $DB->query($sql);
  5116. if ($query->num_rows == 0)
  5117. {
  5118. return $DSP->set_return_data(
  5119. $LANG->line('admin').$DSP->crumb_item($LANG->line('field_groups')),
  5120. $DSP->heading($LANG->line('field_groups')).
  5121. stripslashes($message).
  5122. $DSP->qdiv('itemWrapper', $LANG->line('no_field_group_message')).
  5123. $DSP->qdiv('itmeWrapper',
  5124. $DSP->anchor(
  5125. BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=field_group_editor',
  5126. $LANG->line('create_new_field_group')
  5127. )),
  5128. $LANG->line('field_groups')
  5129. );
  5130. }
  5131. $r = '';
  5132. if ($message != '')
  5133. {
  5134. $r .= $DSP->qdiv('box', stripslashes($message));
  5135. }
  5136. $r .= $DSP->table('tableBorder', '0', '', '100%').
  5137. $DSP->tr().
  5138. $DSP->td('tableHeading', '', '4').
  5139. $LANG->line('field_group').
  5140. $DSP->td_c().
  5141. $DSP->tr_c();
  5142. $i = 0;
  5143. foreach($query->result as $row)
  5144. {
  5145. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  5146. $r .= $DSP->tr().
  5147. $DSP->table_qcell($style, $DSP->qspan('defaultBold', $row['group_name']));
  5148. $r .= $DSP->table_qcell($style,
  5149. '('.$row['count'].')'.$DSP->nbs(2).
  5150. $DSP->anchor(
  5151. BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=field_editor'.AMP.'group_id='.$row['group_id'],
  5152. $LANG->line('add_edit_fields')
  5153. ));
  5154. $r .= $DSP->table_qcell($style,
  5155. $DSP->anchor(
  5156. BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=field_group_editor'.AMP.'group_id='.$row['group_id'],
  5157. $LANG->line('edit_field_group_name')
  5158. ));
  5159. $r .= $DSP->table_qcell($style,
  5160. $DSP->anchor(
  5161. BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=del_field_group_conf'.AMP.'group_id='.$row['group_id'],
  5162. $LANG->line('delete_field_group')
  5163. ));
  5164. $r .= $DSP->tr_c();
  5165. }
  5166. $r .= $DSP->table_c();
  5167. $DSP->title = $LANG->line('field_groups');
  5168. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  5169. $DSP->crumb_item($LANG->line('field_groups'));
  5170. $DSP->right_crumb($LANG->line('create_new_field_group'), BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=field_group_editor');
  5171. $DSP->body = $r;
  5172. }
  5173. /* END */
  5174. /** -----------------------------------------------------------
  5175. /** New/edit field group form
  5176. /** -----------------------------------------------------------*/
  5177. // This function lets you create/edit a custom field group
  5178. //-----------------------------------------------------------
  5179. function edit_field_group_form()
  5180. {
  5181. global $DSP, $IN, $DB, $REGX, $LANG;
  5182. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  5183. {
  5184. return $DSP->no_access_message();
  5185. }
  5186. // Set default values
  5187. $edit = FALSE;
  5188. $group_id = '';
  5189. $group_name = '';
  5190. // If we have the group_id variable it's an edit request, so fetch the field data
  5191. if ($group_id = $IN->GBL('group_id'))
  5192. {
  5193. $edit = TRUE;
  5194. if ( ! is_numeric($group_id))
  5195. {
  5196. return FALSE;
  5197. }
  5198. $query = $DB->query("SELECT group_name, group_id FROM exp_field_groups WHERE group_id = '".$DB->escape_str($group_id)."'");
  5199. foreach ($query->row as $key => $val)
  5200. {
  5201. $$key = $val;
  5202. }
  5203. }
  5204. if ($edit == FALSE)
  5205. $title = $LANG->line('new_field_group');
  5206. else
  5207. $title = $LANG->line('edit_field_group_name');
  5208. // Build our output
  5209. $r = $DSP->form_open(array('action' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=update_field_group'));
  5210. if ($edit == TRUE)
  5211. $r .= $DSP->input_hidden('group_id', $group_id);
  5212. $r .= $DSP->qdiv('tableHeading', $title);
  5213. $r .= $DSP->div('box');
  5214. $r .= $DSP->qdiv('itemWrapper', $DSP->qdiv('defaultBold', $LANG->line('field_group_name', 'group_name')));
  5215. $r .= $DSP->input_text('group_name', $group_name, '20', '50', 'input', '300px');
  5216. $r .= $DSP->br(2);
  5217. $r .= $DSP->div_c();
  5218. $r .= $DSP->div('itemWrapperTop');
  5219. if ($edit == FALSE)
  5220. $r .= $DSP->input_submit($LANG->line('submit'));
  5221. else
  5222. $r .= $DSP->input_submit($LANG->line('update'));
  5223. $r .= $DSP->div_c();
  5224. $r .= $DSP->form_close();
  5225. $DSP->title = $title;
  5226. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  5227. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=custom_fields', $LANG->line('field_groups'))).
  5228. $DSP->crumb_item($title);
  5229. $DSP->body = $r;
  5230. }
  5231. /* END */
  5232. /** -----------------------------------------------------------
  5233. /** Field group submission handler
  5234. /** -----------------------------------------------------------*/
  5235. // This function receives the submitted group data and puts
  5236. // it in the database
  5237. //-----------------------------------------------------------
  5238. function update_field_group()
  5239. {
  5240. global $DSP, $IN, $DB, $LOG, $LANG, $PREFS;
  5241. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  5242. {
  5243. return $DSP->no_access_message();
  5244. }
  5245. // If the $group_id variable is present we are editing an
  5246. // existing group, otherwise we are creating a new one
  5247. $edit = (isset($_POST['group_id'])) ? TRUE : FALSE;
  5248. if ($_POST['group_name'] == '')
  5249. {
  5250. return $this->edit_field_group_form();
  5251. }
  5252. if ( ! preg_match("#^[a-zA-Z0-9_\-/\s]+$#i", $_POST['group_name']))
  5253. {
  5254. return $DSP->error_message($LANG->line('illegal_characters'));
  5255. }
  5256. // Is the group name taken?
  5257. $sql = "SELECT COUNT(*) AS count FROM exp_field_groups WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND group_name = '".$DB->escape_str($_POST['group_name'])."'";
  5258. if ($edit == TRUE)
  5259. {
  5260. $sql .= " AND group_id != '".$DB->escape_str($_POST['group_id'])."'";
  5261. }
  5262. $query = $DB->query($sql);
  5263. if ($query->row['count'] > 0)
  5264. {
  5265. return $DSP->error_message($LANG->line('taken_field_group_name'));
  5266. }
  5267. // Construct the query based on whether we are updating or inserting
  5268. if ($edit == FALSE)
  5269. {
  5270. unset($_POST['group_id']);
  5271. $_POST['site_id'] = $PREFS->ini('site_id');
  5272. $sql = $DB->insert_string('exp_field_groups', $_POST);
  5273. $success_msg = $LANG->line('field_group_created');
  5274. $crumb = $DSP->crumb_item($LANG->line('new_field_group'));
  5275. $LOG->log_action($LANG->line('field_group_created').$DSP->nbs(2).$_POST['group_name']);
  5276. }
  5277. else
  5278. {
  5279. $sql = $DB->update_string('exp_field_groups', $_POST, 'group_id='.$_POST['group_id']);
  5280. $success_msg = $LANG->line('field_group_updated');
  5281. $crumb = $DSP->crumb_item($LANG->line('update'));
  5282. }
  5283. $DB->query($sql);
  5284. $message = $DSP->qdiv('itemWrapper', $DSP->qspan('success', $success_msg.$DSP->nbs(2)).$DSP->qspan('defaultBold', $_POST['group_name']));
  5285. if ($edit == FALSE)
  5286. {
  5287. $query = $DB->query("SELECT weblog_id from exp_weblogs WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND is_user_blog = 'n'");
  5288. if ($query->num_rows > 0)
  5289. {
  5290. $message .= $DSP->div('itemWrapper').$DSP->qspan('highlight', $LANG->line('assign_group_to_weblog')).$DSP->nbs(2);
  5291. if ($query->num_rows == 1)
  5292. {
  5293. $link = 'C=admin'.AMP.'M=blog_admin'.AMP.'P=group_prefs'.AMP.'weblog_id='.$query->row['weblog_id'];
  5294. }
  5295. else
  5296. {
  5297. $link = 'C=admin'.AMP.'M=blog_admin'.AMP.'P=blog_list';
  5298. }
  5299. $message .= $DSP->anchor(BASE.AMP.$link, $LANG->line('click_to_assign_group'));
  5300. $message .= $DSP->div_c();
  5301. }
  5302. }
  5303. return $this->field_overview($message);
  5304. }
  5305. /* END */
  5306. /** -----------------------------------------------------------
  5307. /** Delete field group confirm
  5308. /** -----------------------------------------------------------*/
  5309. // Warning message if you try to delete a field group
  5310. //-----------------------------------------------------------
  5311. function delete_field_group_conf()
  5312. {
  5313. global $DSP, $IN, $DB, $LANG;
  5314. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  5315. {
  5316. return $DSP->no_access_message();
  5317. }
  5318. if (($group_id = $IN->GBL('group_id')) === FALSE OR ! is_numeric($group_id))
  5319. {
  5320. return FALSE;
  5321. }
  5322. $query = $DB->query("SELECT group_name FROM exp_field_groups WHERE group_id = '".$DB->escape_str($group_id)."'");
  5323. $DSP->title = $LANG->line('delete_group');
  5324. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  5325. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=custom_fields', $LANG->line('field_groups'))).
  5326. $DSP->crumb_item($LANG->line('delete_group'));
  5327. $DSP->body = $DSP->delete_confirmation(
  5328. array(
  5329. 'url' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=delete_field_group'.AMP.'group_id='.$group_id,
  5330. 'heading' => 'delete_field_group',
  5331. 'message' => 'delete_field_group_confirmation',
  5332. 'item' => $query->row['group_name'],
  5333. 'extra' => '',
  5334. 'hidden' => array('group_id' => $group_id)
  5335. )
  5336. );
  5337. }
  5338. /* END */
  5339. /** -------------------------------------------
  5340. /** Delete field group
  5341. /** -------------------------------------------*/
  5342. function delete_field_group()
  5343. {
  5344. global $DSP, $FNS, $IN, $DB, $LOG, $LANG;
  5345. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  5346. {
  5347. return $DSP->no_access_message();
  5348. }
  5349. if (($group_id = $IN->GBL('group_id')) === FALSE OR ! is_numeric($group_id))
  5350. {
  5351. return FALSE;
  5352. }
  5353. $query = $DB->query("SELECT group_name FROM exp_field_groups WHERE group_id = '".$DB->escape_str($group_id)."'");
  5354. $name = $query->row['group_name'];
  5355. $query = $DB->query("SELECT field_id, field_type FROM exp_weblog_fields WHERE group_id ='$group_id'");
  5356. if ($query->num_rows > 0)
  5357. {
  5358. foreach ($query->result as $row)
  5359. {
  5360. $DB->query("ALTER TABLE exp_weblog_data DROP COLUMN field_id_".$row['field_id']);
  5361. $DB->query("ALTER TABLE exp_weblog_data DROP COLUMN field_ft_".$row['field_id']);
  5362. if ($row['field_type'] == 'date')
  5363. {
  5364. $DB->query("ALTER TABLE exp_weblog_data DROP COLUMN field_dt_".$row['field_id']);
  5365. }
  5366. $DB->query("DELETE FROM exp_field_formatting WHERE field_id = '".$DB->escape_str($row['field_id'])."'");
  5367. $DB->query("UPDATE exp_weblogs SET search_excerpt = 0 WHERE search_excerpt = '".$DB->escape_str($row['field_id'])."'");
  5368. }
  5369. }
  5370. $DB->query("DELETE FROM exp_field_groups WHERE group_id = '".$DB->escape_str($group_id)."'");
  5371. $DB->query("DELETE FROM exp_weblog_fields WHERE group_id = '".$DB->escape_str($group_id)."'");
  5372. $LOG->log_action($LANG->line('field_group_deleted').$DSP->nbs(2).$name);
  5373. $message = $DSP->qdiv('itemWrapper', $DSP->qspan('success', $LANG->line('field_group_deleted')).NBS.NBS.'<b>'.$name.'</b>');
  5374. $FNS->clear_caching('all', '', TRUE);
  5375. return $this->field_overview($message);
  5376. }
  5377. /* END */
  5378. /** -----------------------------------------------------------
  5379. /** Field manager
  5380. /** -----------------------------------------------------------*/
  5381. // This function show a list of current fields and the
  5382. // form that allows you to create a new field.
  5383. //-----------------------------------------------------------
  5384. function field_manager($group_id = '', $msg = FALSE)
  5385. {
  5386. global $DSP, $IN, $DB, $LANG;
  5387. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  5388. {
  5389. return $DSP->no_access_message();
  5390. }
  5391. $message = ($msg == TRUE) ? $DSP->qdiv('success', $LANG->line('preferences_updated')) : '';
  5392. if ($group_id == '')
  5393. {
  5394. if (($group_id = $IN->GBL('group_id')) === FALSE OR ! is_numeric($group_id))
  5395. {
  5396. return FALSE;
  5397. }
  5398. }
  5399. elseif ( ! is_numeric($group_id))
  5400. {
  5401. return FALSE;
  5402. }
  5403. // Fetch the name of the field group
  5404. $query = $DB->query("SELECT group_name FROM exp_field_groups WHERE group_id = '".$DB->escape_str($group_id)."'");
  5405. $r = $DSP->qdiv('tableHeading', $LANG->line('field_group').':'.$DSP->nbs(2).$query->row['group_name']);
  5406. if ($message != '')
  5407. {
  5408. $r .= $DSP->qdiv('box', stripslashes($message));
  5409. }
  5410. $r .= $DSP->table('tableBorder', '0', '10', '100%').
  5411. $DSP->tr().
  5412. $DSP->td('tableHeadingAlt', '40%', '1').$LANG->line('field_label').$DSP->td_c().
  5413. $DSP->td('tableHeadingAlt', '20%', '1').$LANG->line('field_name').$DSP->td_c().
  5414. $DSP->td('tableHeadingAlt', '40%', '2').$LANG->line('field_type').$DSP->td_c().
  5415. $DSP->tr_c();
  5416. $query = $DB->query("SELECT field_id, field_order, field_name, field_label, field_type FROM exp_weblog_fields WHERE group_id = '".$DB->escape_str($group_id)."' ORDER BY field_order");
  5417. if ($query->num_rows == 0)
  5418. {
  5419. $r .= $DSP->tr().
  5420. $DSP->td('tableCellTwo', '', 3).
  5421. '<b>'.$LANG->line('no_field_groups').'</br>'.
  5422. $DSP->td_c().
  5423. $DSP->tr_c();
  5424. }
  5425. $i = 0;
  5426. if ($query->num_rows > 0)
  5427. {
  5428. foreach ($query->result as $row)
  5429. {
  5430. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  5431. $r .= $DSP->tr();
  5432. $r .= $DSP->table_qcell($style, $DSP->qdiv('defaultBold', $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=edit_field'.AMP.'field_id='.$row['field_id'], $row['field_order'].$DSP->nbs(2).$row['field_label'])));
  5433. $r .= $DSP->table_qcell($style, $row['field_name']);
  5434. $field_type = ($LANG->line($row['field_type']) === FALSE) ? '' : $LANG->line($row['field_type']);
  5435. switch ($row['field_type'])
  5436. {
  5437. case 'text' : $field_type = $LANG->line('text_input');
  5438. break;
  5439. case 'textarea' : $field_type = $LANG->line('textarea');
  5440. break;
  5441. case 'select' : $field_type = $LANG->line('select_list');
  5442. break;
  5443. case 'date' : $field_type = $LANG->line('date_field');
  5444. break;
  5445. case 'rel' : $field_type = $LANG->line('relationship');
  5446. break;
  5447. }
  5448. $r .= $DSP->table_qcell($style, $field_type);
  5449. $r .= $DSP->table_qcell($style, $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=del_field_conf'.AMP.'field_id='.$row['field_id'], $LANG->line('delete')));
  5450. $r .= $DSP->tr_c();
  5451. }
  5452. }
  5453. $r .= $DSP->table_c();
  5454. if ($query->num_rows > 0)
  5455. {
  5456. $r .= $DSP->qdiv('paddedWrapper', $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=edit_field_order'.AMP.'group_id='.$group_id, $LANG->line('edit_field_order')));
  5457. }
  5458. $DSP->title = $LANG->line('custom_fields');
  5459. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  5460. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=custom_fields', $LANG->line('field_groups'))).
  5461. $DSP->crumb_item($LANG->line('custom_fields'));
  5462. $DSP->right_crumb($LANG->line('create_new_custom_field'), BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=edit_field'.AMP.'group_id='.$group_id);
  5463. $DSP->body = $r;
  5464. }
  5465. /* END */
  5466. /** -----------------------------------------------------------
  5467. /** Edit field form
  5468. /** -----------------------------------------------------------*/
  5469. // This function lets you edit an existing custom field
  5470. //-----------------------------------------------------------
  5471. function edit_field_form()
  5472. {
  5473. global $DSP, $IN, $DB, $REGX, $LANG, $EXT, $PREFS;
  5474. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  5475. {
  5476. return $DSP->no_access_message();
  5477. }
  5478. $field_id = $IN->GBL('field_id');
  5479. $type = ($field_id) ? 'edit' : 'new';
  5480. $total_fields = '';
  5481. if ($type == 'new')
  5482. {
  5483. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_weblog_fields WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'");
  5484. $total_fields = $query->row['count'] + 1;
  5485. }
  5486. $DB->fetch_fields = TRUE;
  5487. $query = $DB->query("SELECT f.*, g.group_name FROM exp_weblog_fields AS f, exp_field_groups AS g
  5488. WHERE f.group_id = g.group_id
  5489. AND g.site_id = '".$DB->escape_str($PREFS->ini('site_id'))."'
  5490. AND f.field_id = '{$field_id}'");
  5491. $data = array();
  5492. if ($query->num_rows == 0)
  5493. {
  5494. foreach ($query->fields as $f)
  5495. {
  5496. $data[$f] = '';
  5497. $$f = '';
  5498. }
  5499. }
  5500. else
  5501. {
  5502. foreach ($query->row as $key => $val)
  5503. {
  5504. $data[$key] = $val;
  5505. $$key = $val;
  5506. }
  5507. }
  5508. if ($group_id == '')
  5509. {
  5510. $group_id = $IN->GBL('group_id');
  5511. }
  5512. // Adjust $group_name for new custom fields
  5513. // as we display this later
  5514. if ($group_name == '')
  5515. {
  5516. $query = $DB->query("SELECT group_name FROM exp_field_groups WHERE group_id = '{$group_id}'");
  5517. if ($query->num_rows > 0)
  5518. {
  5519. $group_name = $query->row['group_name'];
  5520. }
  5521. }
  5522. // Is the gallery installed?
  5523. // We check this here so that the JS can know
  5524. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_modules WHERE module_name = 'Gallery'");
  5525. $is_gallery_installed = ($query->row['count'] == 0) ? FALSE : TRUE;
  5526. // JavaScript Stuff
  5527. $val = $LANG->line('field_val');
  5528. $r = "";
  5529. ob_start();
  5530. ?>
  5531. <script type="text/javascript">
  5532. <!--
  5533. function showhide_element(id)
  5534. {
  5535. if (id == 'text')
  5536. {
  5537. document.getElementById('text_block').style.display = "block";
  5538. document.getElementById('textarea_block').style.display = "none";
  5539. document.getElementById('select_block').style.display = "none";
  5540. document.getElementById('pre_populate').style.display = "none";
  5541. document.getElementById('date_block').style.display = "none";
  5542. document.getElementById('rel_block').style.display = "none";
  5543. document.getElementById('relationship_type').style.display = "none";
  5544. document.getElementById('formatting_block').style.display = "block";
  5545. document.getElementById('formatting_unavailable').style.display = "none";
  5546. document.getElementById('direction_available').style.display = "block";
  5547. document.getElementById('direction_unavailable').style.display = "none";
  5548. }
  5549. else if (id == 'textarea')
  5550. {
  5551. document.getElementById('textarea_block').style.display = "block";
  5552. document.getElementById('text_block').style.display = "none";
  5553. document.getElementById('select_block').style.display = "none";
  5554. document.getElementById('pre_populate').style.display = "none";
  5555. document.getElementById('date_block').style.display = "none";
  5556. document.getElementById('rel_block').style.display = "none";
  5557. document.getElementById('relationship_type').style.display = "none";
  5558. document.getElementById('formatting_block').style.display = "block";
  5559. document.getElementById('formatting_unavailable').style.display = "none";
  5560. document.getElementById('direction_available').style.display = "block";
  5561. document.getElementById('direction_unavailable').style.display = "none";
  5562. }
  5563. else if (id == 'select')
  5564. {
  5565. document.getElementById('select_block').style.display = "block";
  5566. document.getElementById('pre_populate').style.display = "block";
  5567. document.getElementById('text_block').style.display = "none";
  5568. document.getElementById('textarea_block').style.display = "none";
  5569. document.getElementById('date_block').style.display = "none";
  5570. document.getElementById('rel_block').style.display = "none";
  5571. document.getElementById('relationship_type').style.display = "none";
  5572. document.getElementById('formatting_block').style.display = "block";
  5573. document.getElementById('formatting_unavailable').style.display = "none";
  5574. document.getElementById('direction_available').style.display = "block";
  5575. document.getElementById('direction_unavailable').style.display = "none";
  5576. }
  5577. else if (id == 'date')
  5578. {
  5579. document.getElementById('date_block').style.display = "block";
  5580. document.getElementById('select_block').style.display = "none";
  5581. document.getElementById('pre_populate').style.display = "none";
  5582. document.getElementById('text_block').style.display = "none";
  5583. document.getElementById('textarea_block').style.display = "none";
  5584. document.getElementById('rel_block').style.display = "none";
  5585. document.getElementById('relationship_type').style.display = "none";
  5586. document.getElementById('formatting_block').style.display = "none";
  5587. document.getElementById('formatting_unavailable').style.display = "block";
  5588. document.getElementById('direction_available').style.display = "none";
  5589. document.getElementById('direction_unavailable').style.display = "block";
  5590. <?php if ($field_id != "") echo 'format_update_block(1,1);'; ?>
  5591. }
  5592. else if (id == 'rel')
  5593. {
  5594. document.getElementById('rel_block').style.display = "block";
  5595. document.getElementById('select_block').style.display = "none";
  5596. document.getElementById('pre_populate').style.display = "none";
  5597. document.getElementById('text_block').style.display = "none";
  5598. document.getElementById('textarea_block').style.display = "none";
  5599. document.getElementById('date_block').style.display = "none";
  5600. document.getElementById('relationship_type').style.display = "block";
  5601. document.getElementById('formatting_block').style.display = "none";
  5602. document.getElementById('formatting_unavailable').style.display = "block";
  5603. document.getElementById('direction_available').style.display = "block";
  5604. document.getElementById('direction_unavailable').style.display = "none";
  5605. <?php if ($field_id != "") echo 'format_update_block(1,1);'; ?>
  5606. }
  5607. }
  5608. function pre_populate(id)
  5609. {
  5610. if (id == 'n')
  5611. {
  5612. document.getElementById('populate_block_man').style.display = "block";
  5613. document.getElementById('populate_block_blog').style.display = "none";
  5614. }
  5615. else
  5616. {
  5617. document.getElementById('populate_block_blog').style.display = "block";
  5618. document.getElementById('populate_block_man').style.display = "none";
  5619. }
  5620. }
  5621. function relationship_type(id)
  5622. {
  5623. if (id == 'blog')
  5624. {
  5625. document.getElementById('related_block_blog').style.display = "block";
  5626. document.getElementById('sortorder_block').style.display = "block";
  5627. document.getElementById('related_block_gallery').style.display = "none";
  5628. }
  5629. else
  5630. {
  5631. document.getElementById('related_block_gallery').style.display = "block";
  5632. document.getElementById('related_block_blog').style.display = "none";
  5633. <?php
  5634. if ($is_gallery_installed == FALSE)
  5635. {
  5636. ?>
  5637. document.getElementById('sortorder_block').style.display = "none";
  5638. <?php
  5639. }
  5640. ?>
  5641. }
  5642. }
  5643. function format_update_block(oldfmt, newfmt)
  5644. {
  5645. if (oldfmt == newfmt)
  5646. {
  5647. document.getElementById('update_formatting').style.display = "none";
  5648. document.field_form.update_formatting.checked=false;
  5649. }
  5650. else
  5651. {
  5652. document.getElementById('update_formatting').style.display = "block";
  5653. }
  5654. }
  5655. function validate(id)
  5656. {
  5657. if (id == "")
  5658. {
  5659. alert("<?php echo $LANG->line('field_val'); ?>");
  5660. return FALSE;
  5661. }
  5662. }
  5663. -->
  5664. </script>
  5665. <?php
  5666. $js = ob_get_contents();
  5667. ob_end_clean();
  5668. /* -------------------------------------------
  5669. /* 'publish_admin_edit_field_js' hook.
  5670. /* - Allows modifying or adding onto Custom Weblog Field JS
  5671. /* - Added 1.4.2
  5672. */
  5673. if ($EXT->active_hook('publish_admin_edit_field_js') === TRUE)
  5674. {
  5675. $js = $EXT->call_extension('publish_admin_edit_field_js', $data, $js);
  5676. }
  5677. /*
  5678. /* -------------------------------------------*/
  5679. $r .= $js;
  5680. $r .= NL.NL;
  5681. $typopts = '';
  5682. // Form declaration
  5683. $r .= $DSP->form_open(array('action' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=update_weblog_fields', 'name' => 'field_form'));
  5684. $r .= $DSP->input_hidden('group_id', $group_id);
  5685. $r .= $DSP->input_hidden('field_id', $field_id);
  5686. $r .= $DSP->input_hidden('site_id', $PREFS->ini('site_id'));
  5687. $title = ($type == 'edit') ? 'edit_field' : 'create_new_custom_field';
  5688. $r .= $DSP->table('tableBorder', '0', '10', '100%').
  5689. $DSP->tr().
  5690. $DSP->td('tableHeading', '', '2').$LANG->line($title).NBS.NBS."(".$LANG->line('field_group').": {$group_name})".$DSP->td_c().
  5691. $DSP->tr_c();
  5692. $i = 0;
  5693. /** ---------------------------------
  5694. /** Field name
  5695. /** ---------------------------------*/
  5696. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  5697. $r .= $DSP->tr();
  5698. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $DSP->required().NBS.$LANG->line('field_name', 'field_name')).$DSP->qdiv('itemWrapper', $LANG->line('field_name_cont')), '50%');
  5699. $r .= $DSP->table_qcell($style, $DSP->input_text('field_name', $field_name, '20', '60', 'input', '260px'), '50%');
  5700. $r .= $DSP->tr_c();
  5701. /** ---------------------------------
  5702. /** Field Label
  5703. /** ---------------------------------*/
  5704. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  5705. $r .= $DSP->tr();
  5706. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $DSP->required().NBS.$LANG->line('field_label', 'field_label')).$DSP->qdiv('', $LANG->line('field_label_info')), '50%');
  5707. $r .= $DSP->table_qcell($style, $DSP->input_text('field_label', $field_label, '20', '60', 'input', '260px'), '50%');
  5708. $r .= $DSP->tr_c();
  5709. /** ---------------------------------
  5710. /** Field Instructions
  5711. /** ---------------------------------*/
  5712. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  5713. $r .= $DSP->tr();
  5714. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('field_instructions', 'field_instructions')).$DSP->qdiv('', $LANG->line('field_instructions_info')), '50%', 'top');
  5715. $r .= $DSP->table_qcell($style, $DSP->input_textarea('field_instructions', $field_instructions, '6', 'textarea', '99%'), '50%', 'top');
  5716. $r .= $DSP->tr_c();
  5717. /** ---------------------------------
  5718. /** Field type
  5719. /** ---------------------------------*/
  5720. $sel_1 = ''; $sel_2 = ''; $sel_3 = ''; $sel_4 = ''; $sel_5 = '';
  5721. $text_js = ($type == 'edit') ? 'none' : 'block';
  5722. $textarea_js = 'none';
  5723. $select_js = 'none';
  5724. $select_opt_js = 'none';
  5725. $date_js = 'none';
  5726. $rel_js = 'none';
  5727. $rel_type_js = 'none';
  5728. switch ($field_type)
  5729. {
  5730. case 'text' : $sel_1 = 1; $text_js = 'block';
  5731. break;
  5732. case 'textarea' : $sel_2 = 1; $textarea_js = 'block';
  5733. break;
  5734. case 'select' : $sel_3 = 1; $select_js = 'block'; $select_opt_js = 'block';
  5735. break;
  5736. case 'date' : $sel_4 = 1; $date_js = 'block';
  5737. break;
  5738. case 'rel' : $sel_5 = 1; $rel_js = 'block'; $rel_type_js = 'block';
  5739. break;
  5740. }
  5741. /** ---------------------------------
  5742. /** Create the pull-down menu
  5743. /** ---------------------------------*/
  5744. $typemenu = "<select name='field_type' class='select' onchange='showhide_element(this.options[this.selectedIndex].value);' >".NL;
  5745. $typemenu .= $DSP->input_select_option('text', $LANG->line('text_input'), $sel_1)
  5746. .$DSP->input_select_option('textarea', $LANG->line('textarea'), $sel_2)
  5747. .$DSP->input_select_option('select', $LANG->line('select_list'), $sel_3)
  5748. .$DSP->input_select_option('date', $LANG->line('date_field'), $sel_4)
  5749. .$DSP->input_select_option('rel', $LANG->line('relationship'), $sel_5);
  5750. /* -------------------------------------------
  5751. /* 'publish_admin_edit_field_type_pulldown' hook.
  5752. /* - Allows modifying or adding onto Custom Weblog Field Type Menu Pulldown
  5753. /* - Added 1.4.2
  5754. */
  5755. if ($EXT->active_hook('publish_admin_edit_field_type_pulldown') === TRUE)
  5756. {
  5757. $typemenu = $EXT->call_extension('publish_admin_edit_field_type_pulldown', $data, $typemenu);
  5758. }
  5759. /*
  5760. /* -------------------------------------------*/
  5761. $typemenu .= $DSP->input_select_footer();
  5762. /** ---------------------------------
  5763. /** Create the "populate" radio buttons
  5764. /** ---------------------------------*/
  5765. if ($field_pre_populate == '')
  5766. $field_pre_populate = 'n';
  5767. $typemenu .= '<div id="pre_populate" style="display: '.$select_opt_js.'; padding:0; margin:5px 0 0 0;">';
  5768. $typemenu .= $DSP->qdiv('default',$DSP->input_radio('field_pre_populate', 'n', ($field_pre_populate == 'n') ? 1 : 0, " onclick=\"pre_populate('n');\"").' '.$LANG->line('field_populate_manually'));
  5769. $typemenu .= $DSP->qdiv('default',$DSP->input_radio('field_pre_populate', 'y', ($field_pre_populate == 'y') ? 1 : 0, " onclick=\"pre_populate('y');\"").' '.$LANG->line('field_populate_from_blog'));
  5770. $typemenu .= $DSP->div_c();
  5771. /** ---------------------------------
  5772. /** Create the "relationship with" radio buttons
  5773. /** ---------------------------------*/
  5774. if ($field_related_to == '')
  5775. $field_related_to = 'blog';
  5776. $typemenu .= '<div id="relationship_type" style="display: '.$rel_type_js.'; padding:0; margin:5px 0 0 0;">';
  5777. $typemenu .= $DSP->qdiv('default',$DSP->input_radio('field_related_to', 'blog', ($field_related_to == 'blog') ? 1 : 0, " onclick=\"relationship_type('blog');\"").' '.$LANG->line('related_to_blog'));
  5778. $typemenu .= $DSP->qdiv('default',$DSP->input_radio('field_related_to', 'gallery', ($field_related_to == 'gallery') ? 1 : 0, " onclick=\"relationship_type('gallery');\"").' '.$LANG->line('related_to_gallery'));
  5779. $typemenu .= $DSP->div_c();
  5780. /* -------------------------------------------
  5781. /* 'publish_admin_edit_field_type_cellone' hook.
  5782. /* - Allows modifying or adding onto Custom Weblog Field Type - First Table Cell
  5783. /* - Added 1.4.2
  5784. */
  5785. if ($EXT->active_hook('publish_admin_edit_field_type_cellone') === TRUE)
  5786. {
  5787. $typemenu = $EXT->call_extension('publish_admin_edit_field_type_cellone', $data, $typemenu);
  5788. }
  5789. /*
  5790. /* -------------------------------------------*/
  5791. /** ---------------------------------
  5792. /** Select List Field
  5793. /** ---------------------------------*/
  5794. $typopts .= '<div id="select_block" style="display: '.$select_js.'; padding:0; margin:5px 0 0 0;">';
  5795. /** ---------------------------------
  5796. /** Populate Manually
  5797. /** ---------------------------------*/
  5798. $man_populate_js = ($field_pre_populate == 'n') ? 'block' : 'none';
  5799. $typopts .= '<div id="populate_block_man" style="display: '.$man_populate_js.'; padding:0; margin:5px 0 0 0;">';
  5800. $typopts .= $DSP->qdiv('defaultBold', $LANG->line('field_list_items', 'field_list_items')).$DSP->qdiv('default', $LANG->line('field_list_instructions')).$DSP->input_textarea('field_list_items', $field_list_items, 10, 'textarea', '400px');
  5801. $typopts .= $DSP->div_c();
  5802. /** ---------------------------------
  5803. /** Populate via an existing field
  5804. /** ---------------------------------*/
  5805. $blog_populate_js = ($field_pre_populate == 'y') ? 'block' : 'none';
  5806. $typopts .= '<div id="populate_block_blog" style="display: '.$blog_populate_js.'; padding:0; margin:5px 0 0 0;">';
  5807. // Fetch the weblog names
  5808. $query = $DB->query("SELECT weblog_id, blog_title, field_group FROM exp_weblogs WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' ORDER BY blog_title asc");
  5809. // Create the drop-down menu
  5810. $typopts .= $DSP->qdiv('itemWrapper', $DSP->qdiv('defaultBold', $LANG->line('select_weblog_for_field')));
  5811. $typopts .= "<select name='field_pre_populate_id' class='select' onchange='validate(this.options[this.selectedIndex].value);' >".NL;
  5812. foreach ($query->result as $row)
  5813. {
  5814. // Fetch the field names
  5815. $rez = $DB->query("SELECT field_id, field_label FROM exp_weblog_fields WHERE group_id = '".$row['field_group']."' ORDER BY field_label asc");
  5816. $typopts .= $DSP->input_select_option('', $row['blog_title']);
  5817. foreach ($rez->result as $frow)
  5818. {
  5819. $sel = ($field_pre_blog_id == $row['weblog_id'] AND $field_pre_field_id == $frow['field_id']) ? 1 : 0;
  5820. $typopts .= $DSP->input_select_option($row['weblog_id'].'_'.$frow['field_id'], NBS.'-'.NBS.$frow['field_label'], $sel);
  5821. }
  5822. }
  5823. $typopts .= $DSP->input_select_footer();
  5824. $typopts .= $DSP->div_c();
  5825. $typopts .= $DSP->div_c();
  5826. /** ---------------------------------
  5827. /** Date type
  5828. /** ---------------------------------*/
  5829. $typopts .= '<div id="date_block" style="display: '.$date_js.'; padding:0; margin:0;">';
  5830. $typopts .= NBS;
  5831. $typopts .= $DSP->div_c();
  5832. /** ---------------------------------
  5833. /** Populate via a relationsihp
  5834. /** ---------------------------------*/
  5835. // Outer DIV for blog and gallery relationships
  5836. $typopts .= '<div id="rel_block" style="display: '.$rel_js.'; padding:0; margin:0;">';
  5837. /** ---------------------------------
  5838. /** Weblog Relationships
  5839. /** ---------------------------------*/
  5840. $related_to_block = ($field_related_to == 'blog') ? 'block' : 'none';
  5841. $typopts .= '<div id="related_block_blog" style="display: '.$related_to_block.'; padding:0; margin:0;">';
  5842. // Create the drop-down menu
  5843. $typopts .= $DSP->qdiv('itemWrapper', $DSP->qdiv('defaultBold', $LANG->line('select_related_blog')));
  5844. // Fetch the weblog names
  5845. $sql = "SELECT weblog_id, blog_title, site_label FROM exp_weblogs, exp_sites
  5846. WHERE exp_weblogs.site_id = exp_sites.site_id ";
  5847. if ($PREFS->ini('multiple_sites_enabled') !== 'y')
  5848. {
  5849. $sql .= "AND exp_weblogs.site_id = '1' ";
  5850. }
  5851. $query = $DB->query($sql."ORDER BY blog_title asc");
  5852. $typopts .= $DSP->input_select_header('field_related_blog_id');
  5853. foreach ($query->result as $row)
  5854. {
  5855. $sel = ($field_related_id == $row['weblog_id']) ? 1 : 0;
  5856. $typopts .= $DSP->input_select_option($row['weblog_id'], ($PREFS->ini('multiple_sites_enabled') == 'y') ? $row['site_label'].NBS.'-'.NBS.$row['blog_title'] : $row['blog_title'], $sel);
  5857. }
  5858. $typopts .= $DSP->input_select_footer();
  5859. $typopts .= $DSP->div_c();
  5860. /** ---------------------------------
  5861. /** Gallery Relationships
  5862. /** ---------------------------------*/
  5863. $related_to_block = ($field_related_to == 'gallery') ? 'block' : 'none';
  5864. $typopts .= '<div id="related_block_gallery" style="display: '.$related_to_block.'; padding:0; margin:0;">';
  5865. if ($is_gallery_installed == FALSE)
  5866. {
  5867. $typopts .= $DSP->qdiv('itemWrapper', $DSP->qdiv('highlight', $LANG->line('gallery_not_installed')));
  5868. }
  5869. else
  5870. {
  5871. // Create the drop-down menu
  5872. $typopts .= $DSP->qdiv('itemWrapper', $DSP->qdiv('defaultBold', $LANG->line('select_related_gallery')));
  5873. // Fetch the Gallery Names
  5874. $query = $DB->query("SELECT gallery_id, gallery_full_name FROM exp_galleries ORDER BY gallery_full_name asc");
  5875. $typopts .= $DSP->input_select_header('field_related_gallery_id');
  5876. foreach ($query->result as $row)
  5877. {
  5878. $sel = ($field_related_id == $row['gallery_id']) ? 1 : 0;
  5879. $typopts .= $DSP->input_select_option($row['gallery_id'], $row['gallery_full_name'], $sel);
  5880. }
  5881. $typopts .= $DSP->input_select_footer();
  5882. }
  5883. $typopts .= $DSP->div_c();
  5884. /** ---------------------------------
  5885. /** Sorting for relationships
  5886. /** ---------------------------------*/
  5887. $typopts .= '<div id="sortorder_block" style="display: block; padding:0; margin:0;">';
  5888. $typopts .= $DSP->div('itemWrapper');
  5889. $typopts .= $DSP->qdiv('itemWrapper', $DSP->qdiv('defaultBold', $LANG->line('display_criteria')));
  5890. $typopts .= $DSP->input_select_header('field_related_orderby');
  5891. $typopts .= $DSP->input_select_option('title', $LANG->line('orderby_title'), (($field_related_orderby == '' OR $field_related_orderby == 'title') ? 1 : 0));
  5892. $typopts .= $DSP->input_select_option('date', $LANG->line('orderby_date'), ($field_related_orderby == 'date') ? 1 : 0);
  5893. $typopts .= $DSP->input_select_footer();
  5894. $typopts .= NBS.$LANG->line('in').NBS;
  5895. $typopts .= $DSP->input_select_header('field_related_sort');
  5896. $typopts .= $DSP->input_select_option('desc', $LANG->line('sort_desc'), (($field_related_sort == '' OR $field_related_sort == 'desc') ? 1 : 0));
  5897. $typopts .= $DSP->input_select_option('asc', $LANG->line('sort_asc'), ($field_related_sort == 'asc') ? 1 : 0);
  5898. $typopts .= $DSP->input_select_footer();
  5899. $typopts .= NBS.$LANG->line('limit').NBS;
  5900. $typopts .= $DSP->input_select_header('field_related_max');
  5901. $typopts .= $DSP->input_select_option('0', $LANG->line('all'), (($field_related_max == '' OR $field_related_max == 0) ? 1 : 0));
  5902. $typopts .= $DSP->input_select_option('25', 25, ($field_related_max == 25) ? 1 : 0);
  5903. $typopts .= $DSP->input_select_option('50', 50, ($field_related_max == 50) ? 1 : 0);
  5904. $typopts .= $DSP->input_select_option('100', 100, ($field_related_max == 100) ? 1 : 0);
  5905. $typopts .= $DSP->input_select_option('250', 250, ($field_related_max == 250) ? 1 : 0);
  5906. $typopts .= $DSP->input_select_option('500', 500, ($field_related_max == 500) ? 1 : 0);
  5907. $typopts .= $DSP->input_select_option('1000', 1000, ($field_related_max == 1000) ? 1 : 0);
  5908. $typopts .= $DSP->input_select_footer();
  5909. $typopts .= $DSP->div_c();
  5910. $typopts .= $DSP->div_c();
  5911. /** ---------------------------------
  5912. /** END outer DIV for relationships
  5913. /** ---------------------------------*/
  5914. $typopts .= $DSP->div_c();
  5915. /* -------------------------------------------
  5916. /* 'publish_admin_edit_field_type_celltwo' hook.
  5917. /* - Allows modifying or adding onto Custom Weblog Field Type - Second Table Cell
  5918. /* - Added 1.4.2
  5919. */
  5920. if ($EXT->active_hook('publish_admin_edit_field_type_celltwo') === TRUE)
  5921. {
  5922. $typopts = $EXT->call_extension('publish_admin_edit_field_type_celltwo', $data, $typopts);
  5923. }
  5924. /*
  5925. /* -------------------------------------------*/
  5926. /** ---------------------------------
  5927. /** Max-length Field
  5928. /** ---------------------------------*/
  5929. if ($type != 'edit')
  5930. $field_maxl = 128;
  5931. $z = '<div id="text_block" style="display: '.$text_js.'; padding:0; margin:5px 0 0 0;">';
  5932. $z .= $DSP->qdiv('itemWrapper', NBS.NBS.$DSP->input_text('field_maxl', $field_maxl, '4', '3', 'input', '30px').NBS.$LANG->line('field_max_length', 'field_maxl'));
  5933. $z .= $DSP->div_c();
  5934. /** ---------------------------------
  5935. /** Textarea Row Field
  5936. /** ---------------------------------*/
  5937. if ($type != 'edit')
  5938. $field_ta_rows = 6;
  5939. $z .= '<div id="textarea_block" style="display: '.$textarea_js.'; padding:0; margin:5px 0 0 0;">';
  5940. $z .= $DSP->qdiv('itemWrapper', NBS.NBS.$DSP->input_text('field_ta_rows', $field_ta_rows, '4', '3', 'input', '30px').NBS.$LANG->line('textarea_rows', 'field_ta_rows'));
  5941. $z .= $DSP->div_c();
  5942. /** ---------------------------------
  5943. /** Generate the above items
  5944. /** ---------------------------------*/
  5945. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  5946. $r .= $DSP->tr();
  5947. $r .= $DSP->table_qcell($style, $DSP->qdiv('itemWrapper', $DSP->qspan('defaultBold', $LANG->line('field_type'))).$typemenu.$z, '50%', 'top');
  5948. $r .= $DSP->table_qcell($style, $typopts, '50%');
  5949. $r .= $DSP->tr_c();
  5950. /** ---------------------------------
  5951. /** Show field formatting?
  5952. /** ---------------------------------*/
  5953. if ($field_show_fmt == '')
  5954. $field_show_fmt = 'y';
  5955. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  5956. /** ---------------------------------
  5957. /** Field Formatting
  5958. /** ---------------------------------*/
  5959. if ($field_id != '')
  5960. $typemenu = "<select name='field_fmt' class='select' onchange='format_update_block(this.options[this.selectedIndex].value, \"".$field_fmt."\");' >".NL;
  5961. else
  5962. $typemenu = $DSP->input_select_header('field_fmt');
  5963. if ($type == 'new')
  5964. {
  5965. $menulink = '';
  5966. $typemenu .= $DSP->input_select_option('none', $LANG->line('none'), '')
  5967. .$DSP->input_select_option('br', $LANG->line('auto_br'), '')
  5968. .$DSP->input_select_option('xhtml', $LANG->line('xhtml'), 1);
  5969. }
  5970. else
  5971. {
  5972. $confirm = "onclick=\"if(!confirm('".$LANG->line('list_edit_warning')."')) return false;\"";
  5973. $menulink = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=edit_fmt_buttons'.AMP.'id='.$field_id, '<b>'.$LANG->line('edit_list').'</b>', $confirm);
  5974. $typemenu .= $DSP->input_select_option('none', $LANG->line('none'), ($field_fmt == 'none') ? 1 : '');
  5975. $query = $DB->query("SELECT field_fmt FROM exp_field_formatting WHERE field_id = '$field_id' AND field_fmt != 'none' ORDER BY field_fmt");
  5976. foreach ($query->result as $row)
  5977. {
  5978. $fmtname = ucwords(str_replace('_', ' ', $row['field_fmt']));
  5979. if ($fmtname == 'Br')
  5980. {
  5981. $fmtname = $LANG->line('auto_br');
  5982. }
  5983. elseif ($fmtname == 'Xhtml')
  5984. {
  5985. $fmtname = $LANG->line('xhtml');
  5986. }
  5987. $sel = ($field_fmt == $row['field_fmt']) ? 1 : '';
  5988. $typemenu .= $DSP->input_select_option($row['field_fmt'], $fmtname, $sel);
  5989. }
  5990. }
  5991. $typemenu .= $DSP->input_select_footer();
  5992. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  5993. $formatting_block = ($field_type == 'date' OR $field_type == 'rel') ? 'none' : 'block';
  5994. $y = '<div id="formatting_block" style="display: '.$formatting_block.'; padding:0; margin:0 0 0 0;">';
  5995. $y .= $typemenu.NBS.NBS.$menulink;
  5996. $y .= $DSP->qdiv('itemWrapper', $DSP->input_radio('field_show_fmt', 'y', ($field_show_fmt == 'y') ? 1 : '').$LANG->line('show_formatting_buttons').BR.$DSP->input_radio('field_show_fmt', 'n', ($field_show_fmt == 'n') ? 1 : '').$LANG->line('hide_formatting_buttons'));
  5997. $y .= $DSP->div_c();
  5998. $formatting_block = ($field_type == 'date' OR $field_type == 'rel') ? 'block' : 'none';
  5999. $y .= '<div id="formatting_unavailable" style="display: '.$formatting_block.'; padding:0; margin:0 0 0 0;">';
  6000. $y .= $DSP->qdiv('highlight', $LANG->line('formatting_no_available'));
  6001. $y .= $DSP->div_c();
  6002. /* -------------------------------------------
  6003. /* 'publish_admin_edit_field_format' hook.
  6004. /* - Allows modifying or adding onto Default Text Formatting Cell
  6005. /* - Added 1.4.2
  6006. */
  6007. if ($EXT->active_hook('publish_admin_edit_field_format') === TRUE)
  6008. {
  6009. $y = $EXT->call_extension('publish_admin_edit_field_format', $data, $y);
  6010. }
  6011. /*
  6012. /* -------------------------------------------*/
  6013. $r .= $DSP->tr();
  6014. $r .= $DSP->table_qcell($style, $DSP->qdiv('defaultBold', $LANG->line('deft_field_formatting')), '50%', 'top');
  6015. $r .= $DSP->table_qcell($style, $y, '50%');
  6016. $r .= $DSP->tr_c();
  6017. /** ---------------------------------
  6018. /** Text Direction
  6019. /** ---------------------------------*/
  6020. if ($field_text_direction == '') $field_text_direction = 'ltr';
  6021. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  6022. $direction_available = (in_array($field_type, array('text', 'textarea', 'select', 'rel', ''))) ? 'block' : 'none';
  6023. $direction_unavailable = (in_array($field_type, array('text', 'textarea', 'select', 'rel', ''))) ? 'none' : 'block';
  6024. $r .= $DSP->tr();
  6025. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('text_direction')), '50%');
  6026. $r .= $DSP->table_qcell($style,
  6027. '<div id="direction_available" style="display: '.$direction_available.'; padding:0; margin:0 0 0 0;">'.
  6028. $LANG->line('ltr').$DSP->nbs().
  6029. $DSP->input_radio('field_text_direction', 'ltr', ($field_text_direction == 'ltr') ? 1 : '').
  6030. $DSP->nbs(3).
  6031. $LANG->line('rtl').$DSP->nbs().
  6032. $DSP->input_radio('field_text_direction', 'rtl', ($field_text_direction == 'rtl') ? 1 : '').
  6033. $DSP->div_c().
  6034. '<div id="direction_unavailable" style="display: '.$direction_unavailable.'; padding:0; margin:0 0 0 0;">'.
  6035. $DSP->qdiv('highlight', $LANG->line('direction_unavailable')).
  6036. $DSP->div_c(),
  6037. '50%');
  6038. $r .= $DSP->tr_c();
  6039. /** ---------------------------------
  6040. /** Is field required?
  6041. /** ---------------------------------*/
  6042. if ($field_required == '') $field_required = 'n';
  6043. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  6044. $r .= $DSP->tr();
  6045. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('is_field_required')), '50%');
  6046. $r .= $DSP->table_qcell($style, $LANG->line('yes').$DSP->nbs().$DSP->input_radio('field_required', 'y', ($field_required == 'y') ? 1 : '').$DSP->nbs(3).$LANG->line('no').$DSP->nbs().$DSP->input_radio('field_required', 'n', ($field_required == 'n') ? 1 : ''), '50%');
  6047. $r .= $DSP->tr_c();
  6048. /** ---------------------------------
  6049. /** Is field searchable?
  6050. /** ---------------------------------*/
  6051. if ($field_search == '') $field_search = 'n';
  6052. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  6053. $r .= $DSP->tr();
  6054. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('is_field_searchable')), '50%');
  6055. $r .= $DSP->table_qcell($style, $LANG->line('yes').$DSP->nbs().$DSP->input_radio('field_search', 'y', ($field_search == 'y') ? 1 : '').$DSP->nbs(3).$LANG->line('no').$DSP->nbs().$DSP->input_radio('field_search', 'n', ($field_search == 'n') ? 1 : ''), '50%');
  6056. $r .= $DSP->tr_c();
  6057. /** ---------------------------------
  6058. /** Is field hidden?
  6059. /** ---------------------------------*/
  6060. if ($field_is_hidden == '')
  6061. $field_is_hidden = 'n';
  6062. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  6063. $r .= $DSP->tr();
  6064. $r .= $DSP->table_qcell($style, $DSP->qdiv('defaultBold', $LANG->line('field_is_hidden')).$DSP->qdiv('itemWrapper', $LANG->line('hidden_field_blurb')), '50%');
  6065. $r .= $DSP->table_qcell($style, $LANG->line('yes').$DSP->nbs().$DSP->input_radio('field_is_hidden', 'n', ($field_is_hidden == 'n') ? 1 : '').$DSP->nbs(3).$LANG->line('no').$DSP->nbs().$DSP->input_radio('field_is_hidden', 'y', ($field_is_hidden == 'y') ? 1 : ''), '50%');
  6066. $r .= $DSP->tr_c();
  6067. /** ---------------------------------
  6068. /** Field order
  6069. /** ---------------------------------*/
  6070. if ($type == 'new')
  6071. $field_order = $total_fields;
  6072. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  6073. $r .= $DSP->tr();
  6074. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('field_order', 'field_order')), '50%');
  6075. $r .= $DSP->table_qcell($style, $DSP->input_text('field_order', $field_order, '4', '3', 'input', '30px'), '50%');
  6076. $r .= $DSP->tr_c();
  6077. /* -------------------------------------------
  6078. /* 'publish_admin_edit_field_extra_row' hook.
  6079. /* - Allows modifying or adding onto the Custom Field settings table
  6080. /* - Added 1.4.2
  6081. */
  6082. if ($EXT->active_hook('publish_admin_edit_field_extra_row') === TRUE)
  6083. {
  6084. $r = $EXT->call_extension('publish_admin_edit_field_extra_row', $data, $r);
  6085. }
  6086. /*
  6087. /* -------------------------------------------*/
  6088. $r .= $DSP->table_c();
  6089. $r .= $DSP->div('itemWrapper');
  6090. $r .= $DSP->qdiv('itemWrapper', $DSP->required(1));
  6091. if ($field_id != '')
  6092. {
  6093. $r .= '<div id="update_formatting" style="display: none; padding:0; margin:0 0 0 0;">';
  6094. $r .= $DSP->div('itemWrapper');
  6095. $r .= $DSP->qdiv('alert', $LANG->line('fmt_has_changed'));
  6096. $r .= $DSP->qdiv('itemWrapper', $DSP->input_checkbox('update_formatting', 'y', 0).' '.$DSP->qspan('alert', $LANG->line('update_existing_fields')));
  6097. $r .= $DSP->div_c();
  6098. $r .= $DSP->div_c();
  6099. }
  6100. if ($type == 'edit')
  6101. $r .= $DSP->input_submit($LANG->line('update'));
  6102. else
  6103. $r .= $DSP->input_submit($LANG->line('submit'));
  6104. $r .= $DSP->div_c();
  6105. $r .= $DSP->form_close();
  6106. $DSP->title = $LANG->line('custom_fields');
  6107. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  6108. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=custom_fields', $LANG->line('field_groups'))).
  6109. $DSP->crumb_item($LANG->line('custom_fields'));
  6110. $DSP->body = $r;
  6111. }
  6112. /* END */
  6113. /** -------------------------------------------
  6114. /** Create/update custom fields
  6115. /** -------------------------------------------*/
  6116. function update_weblog_fields()
  6117. {
  6118. global $DSP, $FNS, $IN, $DB, $REGX, $LANG, $PREFS;
  6119. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  6120. {
  6121. return $DSP->no_access_message();
  6122. }
  6123. // If the $field_id variable has data we are editing an
  6124. // existing group, otherwise we are creating a new one
  6125. $edit = ( ! isset($_POST['field_id']) OR $_POST['field_id'] == '') ? FALSE : TRUE;
  6126. // We need this as a variable as we'll unset the array index
  6127. $group_id = $_POST['group_id'];
  6128. if ( ! is_numeric($group_id))
  6129. {
  6130. return FALSE;
  6131. }
  6132. // Check for required fields
  6133. $error = array();
  6134. // little check in case they switched sites in MSM after leaving a window open.
  6135. // otherwise the landing page will be extremely confusing
  6136. if ( ! isset($_POST['site_id']) OR $_POST['site_id'] != $PREFS->ini('site_id'))
  6137. {
  6138. $error[] = $LANG->line('site_id_mismatch');
  6139. }
  6140. if ($_POST['field_name'] == '')
  6141. {
  6142. $error[] = $LANG->line('no_field_name');
  6143. }
  6144. else
  6145. {
  6146. // Is the field one of the reserved words?
  6147. if (in_array($_POST['field_name'], $DSP->invalid_custom_field_names()))
  6148. {
  6149. $error[] = $LANG->line('reserved_word');
  6150. }
  6151. }
  6152. if ($_POST['field_label'] == '')
  6153. {
  6154. $error[] = $LANG->line('no_field_label');
  6155. }
  6156. // Does field name contain invalide characters?
  6157. if ( ! preg_match("#^[a-z0-9\_\-]+$#i", $_POST['field_name']))
  6158. {
  6159. $error[] = $LANG->line('invalid_characters');
  6160. }
  6161. // Is the field name taken?
  6162. $sql = "SELECT COUNT(*) AS count FROM exp_weblog_fields WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND field_name = '".$DB->escape_str($_POST['field_name'])."'";
  6163. if ($edit == TRUE)
  6164. {
  6165. $sql .= " AND group_id != '$group_id'";
  6166. }
  6167. $query = $DB->query($sql);
  6168. if ($query->row['count'] > 0)
  6169. {
  6170. $error[] = $LANG->line('duplicate_field_name');
  6171. }
  6172. // Are there errors to display?
  6173. if (count($error) > 0)
  6174. {
  6175. $str = '';
  6176. foreach ($error as $msg)
  6177. {
  6178. $str .= $msg.BR;
  6179. }
  6180. return $DSP->error_message($str);
  6181. }
  6182. if ($_POST['field_list_items'] != '')
  6183. {
  6184. $_POST['field_list_items'] = $REGX->convert_quotes($_POST['field_list_items']);
  6185. }
  6186. if ( ! isset($_POST['field_pre_populate_id']) OR $_POST['field_pre_populate_id'] == '')
  6187. {
  6188. $_POST['field_pre_populate'] = 'n';
  6189. }
  6190. if ($_POST['field_pre_populate'] == 'y')
  6191. {
  6192. $x = explode('_', $_POST['field_pre_populate_id']);
  6193. $_POST['field_pre_blog_id'] = $x['0'];
  6194. $_POST['field_pre_field_id'] = $x['1'];
  6195. }
  6196. if ($_POST['field_related_to'] == 'blog')
  6197. {
  6198. $_POST['field_related_id'] = (isset($_POST['field_related_blog_id'])) ? $_POST['field_related_blog_id'] : '0';
  6199. }
  6200. else
  6201. {
  6202. $_POST['field_related_id'] = (isset($_POST['field_related_gallery_id'])) ? $_POST['field_related_gallery_id'] : '0';
  6203. }
  6204. unset($_POST['field_related_blog_id']);
  6205. unset($_POST['field_related_gallery_id']);
  6206. unset($_POST['field_pre_populate_id']);
  6207. if ( ! in_array($_POST['field_type'], array('text', 'textarea', 'select', 'rel')))
  6208. {
  6209. $_POST['field_text_direction'] = 'ltr';
  6210. }
  6211. // Construct the query based on whether we are updating or inserting
  6212. if ($edit === TRUE)
  6213. {
  6214. if ( ! is_numeric($_POST['field_id']))
  6215. {
  6216. return FALSE;
  6217. }
  6218. // Date or relationship types don't need formatting.
  6219. if ($_POST['field_type'] == 'date' OR $_POST['field_type'] == 'rel')
  6220. {
  6221. $_POST['field_fmt'] = 'none';
  6222. $_POST['update_formatting'] = 'y';
  6223. }
  6224. // Update the formatting for all existing entries
  6225. if (isset($_POST['update_formatting']))
  6226. $DB->query("UPDATE exp_weblog_data SET field_ft_".$_POST['field_id']." = '".$DB->escape_str($_POST['field_fmt'])."'");
  6227. unset($_POST['group_id']);
  6228. unset($_POST['update_formatting']);
  6229. // Do we need to alter the table in order to deal with a new data type?
  6230. $query = $DB->query("SELECT field_type FROM exp_weblog_fields WHERE field_id = '".$DB->escape_str($_POST['field_id'])."'");
  6231. if ($query->row['field_type'] != $_POST['field_type'])
  6232. {
  6233. if ($query->row['field_type'] == 'rel')
  6234. {
  6235. $rquery = $DB->query("SELECT field_id_".$DB->escape_str($_POST['field_id'])." AS rel_id FROM exp_weblog_data WHERE field_id_".$DB->escape_str($_POST['field_id'])." != '0'");
  6236. if ($rquery->num_rows > 0)
  6237. {
  6238. $rel_ids = array();
  6239. foreach ($rquery->result as $row)
  6240. {
  6241. $rel_ids[] = $row['rel_id'];
  6242. }
  6243. $REL_IDS = "('".implode("', '", $rel_ids)."')";
  6244. $DB->query("DELETE FROM exp_relationships WHERE rel_id IN {$REL_IDS}");
  6245. }
  6246. }
  6247. if ($query->row['field_type'] == 'date')
  6248. {
  6249. $DB->query("ALTER TABLE exp_weblog_data DROP COLUMN `field_dt_".$DB->escape_str($_POST['field_id'])."`");
  6250. }
  6251. switch($_POST['field_type'])
  6252. {
  6253. case 'date' :
  6254. $DB->query("ALTER TABLE exp_weblog_data CHANGE COLUMN field_id_".$DB->escape_str($_POST['field_id'])." field_id_".$DB->escape_str($_POST['field_id'])." int(10) NOT NULL");
  6255. $DB->query("ALTER table exp_weblog_data CHANGE COLUMN field_ft_".$DB->escape_str($_POST['field_id'])." field_ft_".$DB->escape_str($_POST['field_id'])." tinytext NULL");
  6256. $DB->query("ALTER TABLE exp_weblog_data ADD COLUMN field_dt_".$DB->escape_str($_POST['field_id'])." varchar(8) NOT NULL AFTER field_ft_".$DB->escape_str($_POST['field_id'])."");
  6257. break;
  6258. case 'rel' :
  6259. $DB->query("ALTER TABLE exp_weblog_data CHANGE COLUMN field_id_".$DB->escape_str($_POST['field_id'])." field_id_".$DB->escape_str($_POST['field_id'])." int(10) NOT NULL");
  6260. $DB->query("ALTER table exp_weblog_data CHANGE COLUMN field_ft_".$DB->escape_str($_POST['field_id'])." field_ft_".$DB->escape_str($_POST['field_id'])." tinytext NULL");
  6261. break;
  6262. default :
  6263. $DB->query("ALTER TABLE exp_weblog_data CHANGE COLUMN field_id_".$DB->escape_str($_POST['field_id'])." field_id_".$DB->escape_str($_POST['field_id'])." text NOT NULL");
  6264. $DB->query("ALTER table exp_weblog_data CHANGE COLUMN field_ft_".$DB->escape_str($_POST['field_id'])." field_ft_".$DB->escape_str($_POST['field_id'])." tinytext NULL");
  6265. break;
  6266. }
  6267. }
  6268. $DB->query($DB->update_string('exp_weblog_fields', $_POST, 'field_id='.$DB->escape_str($_POST['field_id']).' AND group_id='.$group_id));
  6269. }
  6270. else
  6271. {
  6272. unset($_POST['update_formatting']);
  6273. if ($_POST['field_order'] == 0 || $_POST['field_order'] == '')
  6274. {
  6275. $query = $DB->query("SELECT count(*) AS count FROM exp_weblog_fields WHERE group_id = '".$DB->escape_str($group_id)."'");
  6276. $_POST['field_order'] = $query->row['count'] + 1;
  6277. }
  6278. $DB->query($DB->insert_string('exp_weblog_fields', $_POST));
  6279. $insert_id = $DB->insert_id;
  6280. if ($_POST['field_type'] == 'date' OR $_POST['field_type'] == 'rel')
  6281. {
  6282. $DB->query("ALTER TABLE exp_weblog_data ADD COLUMN field_id_".$insert_id." int(10) NOT NULL");
  6283. $DB->query("ALTER TABLE exp_weblog_data ADD COLUMN field_ft_".$insert_id." tinytext NULL");
  6284. if ($_POST['field_type'] == 'date')
  6285. $DB->query("ALTER TABLE exp_weblog_data ADD COLUMN field_dt_".$insert_id." varchar(8) NOT NULL");
  6286. }
  6287. else
  6288. {
  6289. $DB->query("ALTER TABLE exp_weblog_data ADD COLUMN field_id_".$insert_id." text NOT NULL");
  6290. $DB->query("ALTER TABLE exp_weblog_data ADD COLUMN field_ft_".$insert_id." tinytext NULL");
  6291. $DB->query("UPDATE exp_weblog_data SET field_ft_".$insert_id." = '".$DB->escape_str($_POST['field_fmt'])."'");
  6292. }
  6293. foreach (array('none', 'br', 'xhtml') as $val)
  6294. {
  6295. $DB->query("INSERT INTO exp_field_formatting (field_id, field_fmt) VALUES ('$insert_id', '$val')");
  6296. }
  6297. }
  6298. $FNS->clear_caching('all', '', TRUE);
  6299. return $this->field_manager($group_id, $edit);
  6300. }
  6301. /* END */
  6302. /** -----------------------------------------------------------
  6303. /** Delete field confirm
  6304. /** -----------------------------------------------------------*/
  6305. // Warning message if you try to delete a custom field
  6306. //-----------------------------------------------------------
  6307. function delete_field_conf()
  6308. {
  6309. global $DSP, $IN, $DB, $LANG;
  6310. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  6311. {
  6312. return $DSP->no_access_message();
  6313. }
  6314. if ( ! $field_id = $IN->GBL('field_id'))
  6315. {
  6316. return FALSE;
  6317. }
  6318. $query = $DB->query("SELECT field_label FROM exp_weblog_fields WHERE field_id = '$field_id'");
  6319. $DSP->title = $LANG->line('delete_field');
  6320. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  6321. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=custom_fields', $LANG->line('field_groups'))).
  6322. $DSP->crumb_item($LANG->line('delete_field'));
  6323. $DSP->body = $DSP->delete_confirmation(
  6324. array(
  6325. 'url' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=delete_field'.AMP.'field_id='.$field_id,
  6326. 'heading' => 'delete_field',
  6327. 'message' => 'delete_field_confirmation',
  6328. 'item' => $query->row['field_label'],
  6329. 'extra' => '',
  6330. 'hidden' => array('field_id' => $field_id)
  6331. )
  6332. );
  6333. }
  6334. /* END */
  6335. /** -----------------------------------------------------------
  6336. /** Delete field
  6337. /** -----------------------------------------------------------*/
  6338. // This function alters the "exp_weblog_data" table, dropping
  6339. // the fields
  6340. //-----------------------------------------------------------
  6341. function delete_field()
  6342. {
  6343. global $DSP, $FNS, $IN, $DB, $LOG, $LANG;
  6344. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  6345. {
  6346. return $DSP->no_access_message();
  6347. }
  6348. if ( ! $field_id = $IN->GBL('field_id', 'POST'))
  6349. {
  6350. return FALSE;
  6351. }
  6352. if ( ! is_numeric($field_id))
  6353. {
  6354. return FALSE;
  6355. }
  6356. $query = $DB->query("SELECT group_id, field_type, field_label FROM exp_weblog_fields WHERE field_id = '".$DB->escape_str($field_id)."'");
  6357. $group_id = $query->row['group_id'];
  6358. $field_label = $query->row['field_label'];
  6359. $field_type = $query->row['field_type'];
  6360. if ($field_type == 'rel')
  6361. {
  6362. $rquery = $DB->query("SELECT field_id_".$DB->escape_str($field_id)." AS rel_id FROM exp_weblog_data WHERE field_id_".$DB->escape_str($field_id)." != '0'");
  6363. if ($rquery->num_rows > 0)
  6364. {
  6365. $rel_ids = array();
  6366. foreach ($rquery->result as $row)
  6367. {
  6368. $rel_ids[] = $row['rel_id'];
  6369. }
  6370. $REL_IDS = "('".implode("', '", $rel_ids)."')";
  6371. $DB->query("DELETE FROM exp_relationships WHERE rel_id IN {$REL_IDS}");
  6372. }
  6373. }
  6374. if ($field_type == 'date')
  6375. {
  6376. $DB->query("ALTER TABLE exp_weblog_data DROP COLUMN field_dt_".$DB->escape_str($field_id));
  6377. }
  6378. $DB->query("ALTER TABLE exp_weblog_data DROP COLUMN field_id_".$DB->escape_str($field_id));
  6379. $DB->query("ALTER TABLE exp_weblog_data DROP COLUMN field_ft_".$DB->escape_str($field_id));
  6380. $DB->query("DELETE FROM exp_weblog_fields WHERE field_id = '".$DB->escape_str($field_id)."'");
  6381. $DB->query("DELETE FROM exp_field_formatting WHERE field_id = '".$DB->escape_str($field_id)."'");
  6382. $DB->query("UPDATE exp_weblogs SET search_excerpt = 0 WHERE search_excerpt = '".$DB->escape_str($field_id)."'");
  6383. $LOG->log_action($LANG->line('field_deleted').$DSP->nbs(2).$field_label);
  6384. $FNS->clear_caching('all', '', TRUE);
  6385. return $this->field_manager($group_id);
  6386. }
  6387. /* END */
  6388. /** -----------------------------------------------------------
  6389. /** Edit field order
  6390. /** -----------------------------------------------------------*/
  6391. // This function shows the form that lets you change the
  6392. // order that fields appear in
  6393. //-----------------------------------------------------------
  6394. function edit_field_order_form()
  6395. {
  6396. global $DSP, $IN, $DB, $LANG;
  6397. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  6398. {
  6399. return $DSP->no_access_message();
  6400. }
  6401. if (($group_id = $IN->GBL('group_id')) === FALSE OR ! is_numeric($group_id))
  6402. {
  6403. return FALSE;
  6404. }
  6405. $query = $DB->query("SELECT field_label, field_name, field_order FROM exp_weblog_fields WHERE group_id = '".$DB->escape_str($group_id)."' ORDER BY field_order");
  6406. if ($query->num_rows == 0)
  6407. {
  6408. return FALSE;
  6409. }
  6410. $r = $DSP->form_open(array('action' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=update_field_order'));
  6411. $r .= $DSP->input_hidden('group_id', $group_id);
  6412. $r .= $DSP->table('tableBorder', '0', '10', '100%');
  6413. $r .= $DSP->tr()
  6414. .$DSP->td('tableHeading', '', '2').$LANG->line('edit_field_order').$DSP->td_c()
  6415. .$DSP->tr_c();
  6416. foreach ($query->result as $row)
  6417. {
  6418. $r .= $DSP->tr();
  6419. $r .= $DSP->table_qcell('tableCellOne', $row['field_label'], '40%');
  6420. $r .= $DSP->table_qcell('tableCellOne', $DSP->input_text($row['field_name'], $row['field_order'], '4', '3', 'input', '30px'));
  6421. $r .= $DSP->tr_c();
  6422. }
  6423. $r .= $DSP->table_c();
  6424. $r .= $DSP->qdiv('itemWrapperTop', $DSP->input_submit($LANG->line('update')));
  6425. $r .= $DSP->form_close();
  6426. $DSP->title = $LANG->line('edit_field_order');
  6427. $DSP->crumb =
  6428. $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  6429. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=custom_fields', $LANG->line('field_groups'))).
  6430. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=field_editor'.AMP.'group_id='.$group_id, $LANG->line('custom_fields'))).
  6431. $DSP->crumb_item($LANG->line('edit_field_order'));
  6432. $DSP->body = $r;
  6433. }
  6434. /* END */
  6435. /** -----------------------------------------------------------
  6436. /** Update field order
  6437. /** -----------------------------------------------------------*/
  6438. // This function receives the field order submission
  6439. //-----------------------------------------------------------
  6440. function update_field_order()
  6441. {
  6442. global $DSP, $IN, $DB, $LANG, $PREFS;
  6443. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  6444. {
  6445. return $DSP->no_access_message();
  6446. }
  6447. if ( ! $group_id = $IN->GBL('group_id', 'POST'))
  6448. {
  6449. return FALSE;
  6450. }
  6451. unset($_POST['group_id']);
  6452. foreach ($_POST as $key => $val)
  6453. {
  6454. $DB->query("UPDATE exp_weblog_fields SET field_order = '$val' WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND field_name = '$key'");
  6455. }
  6456. return $this->field_manager($group_id);
  6457. }
  6458. /* END */
  6459. /** -------------------------------------
  6460. /** Fetch installed plugins
  6461. /** -------------------------------------*/
  6462. function fetch_plugins()
  6463. {
  6464. global $PREFS;
  6465. $exclude = array('auto_xhtml');
  6466. $filelist = array('br', 'xhtml');
  6467. if ($fp = @opendir(PATH_PI))
  6468. {
  6469. while (false !== ($file = readdir($fp)))
  6470. {
  6471. if ( preg_match("/pi\.[a-z\_0-9]+?".preg_quote(EXT, '/')."$/", $file))
  6472. {
  6473. $file = substr($file, 3, - strlen(EXT));
  6474. if ( ! in_array($file, $exclude))
  6475. $filelist[] = $file;
  6476. }
  6477. }
  6478. closedir($fp);
  6479. }
  6480. sort($filelist);
  6481. return $filelist;
  6482. }
  6483. /* END */
  6484. /** -----------------------------------------------------------
  6485. /** Edit Formatting Buttons
  6486. /** -----------------------------------------------------------*/
  6487. // This function shows the form that lets you edit the
  6488. // contents of the entry formatting pull-down menu
  6489. //-----------------------------------------------------------
  6490. function edit_formatting_buttons()
  6491. {
  6492. global $DSP, $IN, $DB, $LANG;
  6493. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  6494. {
  6495. return $DSP->no_access_message();
  6496. }
  6497. if ( ! $id = $IN->GBL('id'))
  6498. {
  6499. return FALSE;
  6500. }
  6501. $plugins = $this->fetch_plugins();
  6502. $r = $DSP->form_open(array('action' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=update_fmt_buttons'));
  6503. $r .= $DSP->input_hidden('field_id', $id);
  6504. $r .= $DSP->input_hidden('none', 'y');
  6505. $r .= $DSP->table('tableBorder', '0', '10', '100%');
  6506. $r .= $DSP->tr();
  6507. $r .= $DSP->td('tableHeading', '', '2');
  6508. $r .= $LANG->line('formatting_options');
  6509. $r .= $DSP->td_c();
  6510. $r .= $DSP->tr_c();
  6511. $query = $DB->query("SELECT field_fmt FROM exp_field_formatting WHERE field_id = '$id' AND field_fmt != 'none' ORDER BY field_fmt");
  6512. $plugs = array();
  6513. foreach ($query->result as $row)
  6514. {
  6515. $plugs[] = $row['field_fmt'];
  6516. }
  6517. $i = 0;
  6518. foreach ($plugins as $val)
  6519. {
  6520. $name = ucwords(str_replace('_', ' ', $val));
  6521. if ($name == 'Br')
  6522. {
  6523. $name = $LANG->line('auto_br');
  6524. }
  6525. elseif ($name == 'Xhtml')
  6526. {
  6527. $name = $LANG->line('xhtml');
  6528. }
  6529. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  6530. $r .= $DSP->tr();
  6531. $r .= $DSP->table_qcell($style, $DSP->qdiv('defaultBold', $name));
  6532. $r .= $DSP->table_qcell($style, $LANG->line('yes').$DSP->nbs().$DSP->input_radio($val, 'y', (in_array($val, $plugs)) ? 1 : '').$DSP->nbs(3).$LANG->line('no').$DSP->nbs().$DSP->input_radio($val, 'n', ( ! in_array($val, $plugs)) ? 1 : ''), '60%');
  6533. $r .= $DSP->tr_c();
  6534. }
  6535. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  6536. $r .= $DSP->tr();
  6537. $r .= $DSP->td($style, '', '2');
  6538. $r .= $DSP->qdiv('itemWrapperTop', $DSP->input_submit($LANG->line('update')));
  6539. $r .= $DSP->td_c();
  6540. $r .= $DSP->tr_c();
  6541. $r .= $DSP->table_c();
  6542. $r .= $DSP->form_close();
  6543. $DSP->title = $LANG->line('formatting_options');
  6544. $DSP->crumb =
  6545. $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  6546. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=custom_fields', $LANG->line('field_groups'))).
  6547. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=edit_field'.AMP.'field_id='.$id, $LANG->line('custom_fields'))).
  6548. $DSP->crumb_item($LANG->line('formatting_options'));
  6549. $DSP->body = $r;
  6550. }
  6551. /* END */
  6552. /** ---------------------------------------
  6553. /** Update Formatting Buttons
  6554. /** ---------------------------------------*/
  6555. function update_formatting_buttons()
  6556. {
  6557. global $DSP, $FNS, $IN, $DB;
  6558. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  6559. {
  6560. return $DSP->no_access_message();
  6561. }
  6562. if ( ! $id = $IN->GBL('field_id', 'POST'))
  6563. {
  6564. return FALSE;
  6565. }
  6566. if ( ! is_numeric($id))
  6567. {
  6568. return FALSE;
  6569. }
  6570. unset($_POST['field_id']);
  6571. $DB->query("DELETE FROM exp_field_formatting WHERE field_id = '$id'");
  6572. foreach ($_POST as $key => $val)
  6573. {
  6574. if ($val == 'y')
  6575. $DB->query("INSERT INTO exp_field_formatting (field_id, field_fmt) VALUES ('$id', '$key')");
  6576. }
  6577. $FNS->redirect(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=edit_field'.AMP.'field_id='.$id);
  6578. exit;
  6579. }
  6580. /* END */
  6581. /** -----------------------------------------------------------
  6582. /** HTML Buttons
  6583. /** -----------------------------------------------------------*/
  6584. // This function lets you edit the HTML buttons
  6585. //-----------------------------------------------------------
  6586. function html_buttons($message = '', $id = 0)
  6587. {
  6588. global $IN, $DSP, $REGX, $LANG, $DB, $PREFS;
  6589. if ($id == 0 AND ! $DSP->allowed_group('can_admin_weblogs'))
  6590. {
  6591. return $DSP->no_access_message();
  6592. }
  6593. if ( ! is_numeric($id))
  6594. {
  6595. return FALSE;
  6596. }
  6597. $r = '';
  6598. if ($message != '')
  6599. $r .= $DSP->qdiv('box', stripslashes($message));
  6600. if ($id != 0)
  6601. {
  6602. $r .= $DSP->qdiv('tableHeading', $LANG->line('html_buttons'));
  6603. }
  6604. else
  6605. {
  6606. $r .= $DSP->qdiv('tableHeading', $LANG->line('default_html_buttons'));
  6607. $r .= $DSP->qdiv('box', $LANG->line('define_html_buttons'));
  6608. }
  6609. if ($id === 0)
  6610. {
  6611. $r .= $DSP->form_open(array('action' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=save_html_buttons')).
  6612. $DSP->body .= $DSP->input_hidden('member_id', "$id");
  6613. }
  6614. else
  6615. {
  6616. $r .= $DSP->form_open(array('action' => 'C=myaccount'.AMP.'M=update_htmlbuttons')).
  6617. $DSP->body .= $DSP->input_hidden('member_id', "$id");
  6618. }
  6619. $r .= $DSP->table('tableBorder', '0', '', '100%').
  6620. $DSP->tr().
  6621. $DSP->table_qcell('tableHeadingAlt', $LANG->line('tag_name')).
  6622. $DSP->table_qcell('tableHeadingAlt', $LANG->line('tag_open')).
  6623. $DSP->table_qcell('tableHeadingAlt', $LANG->line('tag_close')).
  6624. $DSP->table_qcell('tableHeadingAlt', $LANG->line('accesskey')).
  6625. $DSP->table_qcell('tableHeadingAlt', $LANG->line('tag_order')).
  6626. $DSP->table_qcell('tableHeadingAlt', $LANG->line('row')).
  6627. $DSP->tr_c();
  6628. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_html_buttons WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND member_id = '$id'");
  6629. $member_id = ($query->row['count'] == 0 AND ! isset($_GET['U'])) ? 0 : $id;
  6630. $query = $DB->query("SELECT * FROM exp_html_buttons WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND member_id = '$member_id' ORDER BY tag_row, tag_order");
  6631. $i = 0;
  6632. if ($query->num_rows > 0)
  6633. {
  6634. foreach ($query->result as $row)
  6635. {
  6636. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  6637. $tag_row = $DSP->input_select_header('tag_row_'.$i);
  6638. $selected = ($row['tag_row'] == '1') ? 1 : '';
  6639. $tag_row .= $DSP->input_select_option('1', '1', $selected);
  6640. $selected = ($row['tag_row'] == '2') ? 1 : '';
  6641. $tag_row .= $DSP->input_select_option('2', '2', $selected);
  6642. $tag_row .= $DSP->input_select_footer();
  6643. $r .= $DSP->tr().
  6644. $DSP->table_qcell($style, $DSP->input_text('tag_name_'.$i, $row['tag_name'], '20', '40', 'input', '100%'), '16%').
  6645. $DSP->table_qcell($style, $DSP->input_text('tag_open_'.$i, $row['tag_open'], '20', '120', 'input', '100%'), '37%').
  6646. $DSP->table_qcell($style, $DSP->input_text('tag_close_'.$i, $row['tag_close'], '20', '120', 'input', '100%'), '37%').
  6647. $DSP->table_qcell($style, $DSP->input_text('accesskey_'.$i, $row['accesskey'], '2', '1', 'input', '30px'), '3%').
  6648. $DSP->table_qcell($style, $DSP->input_text('tag_order_'.$i, $row['tag_order'], '2', '2', 'input', '30px'), '3%').
  6649. $DSP->table_qcell($style, $tag_row, '4%').
  6650. $DSP->tr_c();
  6651. }
  6652. }
  6653. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  6654. $tag_row = $DSP->input_select_header('tag_row_'.$i);
  6655. $tag_row .= $DSP->input_select_option('1', '1', '');
  6656. $tag_row .= $DSP->input_select_option('2', '2', '');
  6657. $tag_row .= $DSP->input_select_footer();
  6658. $r .= $DSP->tr().
  6659. $DSP->table_qcell($style, $DSP->input_text('tag_name_'.$i, '', '20', '40', 'input', '100%'), '16%').
  6660. $DSP->table_qcell($style, $DSP->input_text('tag_open_'.$i, '', '20', '120', 'input', '100%'), '37%').
  6661. $DSP->table_qcell($style, $DSP->input_text('tag_close_'.$i,'', '20', '120', 'input', '100%'), '37%').
  6662. $DSP->table_qcell($style, $DSP->input_text('accesskey_'.$i, '', '2', '1', 'input', '30px'), '3%').
  6663. $DSP->table_qcell($style, $DSP->input_text('tag_order_'.$i, '', '2', '2', 'input', '30px'), '3%').
  6664. $DSP->table_qcell($style, $tag_row, '4%').
  6665. $DSP->tr_c();
  6666. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  6667. $r .= $DSP->tr();
  6668. $r .= $DSP->td($style, '', '6');
  6669. $r .= $DSP->qdiv('highlight', NBS.$LANG->line('htmlbutton_delete_instructions'));
  6670. $r .= $DSP->qdiv('buttonWrapper', $DSP->input_submit($LANG->line('submit')));
  6671. $r .= $DSP->td_c();
  6672. $r .= $DSP->tr_c();
  6673. $r .= $DSP->table_c();
  6674. $r .= $DSP->form_close();
  6675. if ($id == 0)
  6676. {
  6677. $DSP->title = $LANG->line('default_html_buttons');
  6678. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  6679. $DSP->crumb_item($LANG->line('default_html_buttons'));
  6680. $DSP->body = $r;
  6681. }
  6682. else
  6683. {
  6684. return $r;
  6685. }
  6686. }
  6687. /* END */
  6688. /** -----------------------------------------
  6689. /** Save HTML formatting buttons
  6690. /** -----------------------------------------*/
  6691. function save_html_buttons()
  6692. {
  6693. global $IN, $FNS, $LANG, $DB, $DSP, $PREFS;
  6694. $id = $IN->GBL('member_id');
  6695. if ($id == 0 AND ! $DSP->allowed_group('can_admin_weblogs'))
  6696. {
  6697. return $DSP->no_access_message();
  6698. }
  6699. if ( ! is_numeric($id))
  6700. {
  6701. return FALSE;
  6702. }
  6703. $data = array();
  6704. foreach ($_POST as $key => $val)
  6705. {
  6706. if (strstr($key, 'tag_name_') AND $val != '')
  6707. {
  6708. $n = substr($key, 9);
  6709. $data[] = array(
  6710. 'member_id' => $id,
  6711. 'tag_name' => $_POST['tag_name_'.$n],
  6712. 'tag_open' => $_POST['tag_open_'.$n],
  6713. 'tag_close' => $_POST['tag_close_'.$n],
  6714. 'accesskey' => $_POST['accesskey_'.$n],
  6715. 'tag_order' => $_POST['tag_order_'.$n],
  6716. 'tag_row' => $_POST['tag_row_'.$n],
  6717. 'site_id' => $PREFS->ini('site_id'),
  6718. );
  6719. }
  6720. }
  6721. $DB->query("DELETE FROM exp_html_buttons WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND member_id = '$id'");
  6722. foreach ($data as $val)
  6723. {
  6724. $DB->query($DB->insert_string('exp_html_buttons', $val));
  6725. }
  6726. $message = $DSP->qdiv('success', $LANG->line('preferences_updated'));
  6727. if ($id == 0)
  6728. {
  6729. $this->html_buttons($message);
  6730. }
  6731. else
  6732. {
  6733. $FNS->redirect(BASE.AMP.'C=myaccount'.AMP.'M=htmlbuttons'.AMP.'id='.$id.AMP.'U=1');
  6734. exit;
  6735. }
  6736. }
  6737. /* END */
  6738. /** -----------------------------------------------------------
  6739. /** Ping servers
  6740. /** -----------------------------------------------------------*/
  6741. // This function lets you edit the ping servers
  6742. //-----------------------------------------------------------
  6743. function ping_servers($message = '', $id = '0')
  6744. {
  6745. global $IN, $DSP, $REGX, $LANG, $DB, $PREFS;
  6746. if ($id == 0 AND ! $DSP->allowed_group('can_admin_weblogs'))
  6747. {
  6748. return $DSP->no_access_message();
  6749. }
  6750. if ( ! is_numeric($id))
  6751. {
  6752. return FALSE;
  6753. }
  6754. $r = '';
  6755. if ($message != '')
  6756. $r .= $DSP->qdiv('box', stripslashes($message));
  6757. if ($id != 0)
  6758. {
  6759. $r .= $DSP->qdiv('tableHeading', $LANG->line('ping_servers'));
  6760. }
  6761. else
  6762. {
  6763. $r .= $DSP->qdiv('tableHeading', $LANG->line('default_ping_servers'));
  6764. $r .= $DSP->qdiv('box', $LANG->line('define_ping_servers'));
  6765. }
  6766. $r .= $DSP->form_open(array('action' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=save_ping_servers')).
  6767. $DSP->body .= $DSP->input_hidden('member_id', "$id");
  6768. $r .= $DSP->table('tableBorder', '0', '', '100%').
  6769. $DSP->tr().
  6770. $DSP->table_qcell('tableHeadingAlt', $LANG->line('server_name')).
  6771. $DSP->table_qcell('tableHeadingAlt', $LANG->line('server_url')).
  6772. $DSP->table_qcell('tableHeadingAlt', $LANG->line('port')).
  6773. $DSP->table_qcell('tableHeadingAlt', $LANG->line('protocol')).
  6774. $DSP->table_qcell('tableHeadingAlt', $LANG->line('is_default')).
  6775. $DSP->table_qcell('tableHeadingAlt', $LANG->line('server_order')).
  6776. $DSP->tr_c();
  6777. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_ping_servers WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND member_id = '$id'");
  6778. $member_id = ($query->row['count'] == 0 AND ! isset($_GET['U'])) ? 0 : $id;
  6779. $query = $DB->query("SELECT * FROM exp_ping_servers WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND member_id = '$member_id' ORDER BY server_order");
  6780. $i = 0;
  6781. if ($query->num_rows > 0)
  6782. {
  6783. foreach ($query->result as $row)
  6784. {
  6785. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  6786. $protocol = $DSP->input_select_header('ping_protocol_'.$i);
  6787. $protocol .= $DSP->input_select_option('xmlrpc', 'xmlrpc');
  6788. $protocol .= $DSP->input_select_footer();
  6789. $default = $DSP->input_select_header('is_default_'.$i);
  6790. $selected = ($row['is_default'] == 'y') ? 1 : '';
  6791. $default .= $DSP->input_select_option('y', $LANG->line('yes'), $selected);
  6792. $selected = ($row['is_default'] == 'n') ? 1 : '';
  6793. $default .= $DSP->input_select_option('n', $LANG->line('no'), $selected);
  6794. $default .= $DSP->input_select_footer();
  6795. $r .= $DSP->tr().
  6796. $DSP->table_qcell($style, $DSP->input_text('server_name_'.$i, $row['server_name'], '20', '40', 'input', '100%'), '25%').
  6797. $DSP->table_qcell($style, $DSP->input_text('server_url_'.$i, $row['server_url'], '20', '150', 'input', '100%'), '55%').
  6798. $DSP->table_qcell($style, $DSP->input_text('server_port_'.$i, $row['port'], '2', '4', 'input', '30px'), '5%').
  6799. $DSP->table_qcell($style, $protocol, '5%').
  6800. $DSP->table_qcell($style, $default, '5%').
  6801. $DSP->table_qcell($style, $DSP->input_text('server_order_'.$i, $row['server_order'], '2', '3', 'input', '30px'), '5%').
  6802. $DSP->tr_c();
  6803. }
  6804. }
  6805. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  6806. $protocol = $DSP->input_select_header('ping_protocol_'.$i);
  6807. $protocol .= $DSP->input_select_option('xmlrpc', 'xmlrpc');
  6808. $protocol .= $DSP->input_select_footer();
  6809. $default = $DSP->input_select_header('is_default_'.$i);
  6810. $default .= $DSP->input_select_option('y', $LANG->line('yes'));
  6811. $default .= $DSP->input_select_option('n', $LANG->line('no'));
  6812. $default .= $DSP->input_select_footer();
  6813. $r .= $DSP->tr().
  6814. $DSP->table_qcell($style, $DSP->input_text('server_name_'.$i, '', '20', '40', 'input', '100%'), '25%').
  6815. $DSP->table_qcell($style, $DSP->input_text('server_url_'.$i, '', '20', '120', 'input', '100%'), '55%').
  6816. $DSP->table_qcell($style, $DSP->input_text('server_port_'.$i, '80', '2', '4', 'input', '30px'), '5%').
  6817. $DSP->table_qcell($style, $protocol, '5%').
  6818. $DSP->table_qcell($style, $default, '5%').
  6819. $DSP->table_qcell($style, $DSP->input_text('server_order_'.$i, '', '2', '3', 'input', '30px'), '5%').
  6820. $DSP->tr_c();
  6821. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  6822. $r .= $DSP->tr();
  6823. $r .= $DSP->td($style, '', '6');
  6824. $r .= $DSP->qdiv('highlight', NBS.$LANG->line('pingserver_delete_instructions'));
  6825. $r .= $DSP->qdiv('buttonWrapper', $DSP->input_submit($LANG->line('submit')));
  6826. $r .= $DSP->td_c();
  6827. $r .= $DSP->tr_c();
  6828. $r .= $DSP->table_c();
  6829. $r .= $DSP->form_close();
  6830. if ($id == 0)
  6831. {
  6832. $DSP->title = $LANG->line('default_ping_servers');
  6833. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  6834. $DSP->crumb_item($LANG->line('default_ping_servers'));
  6835. $DSP->body = $r;
  6836. }
  6837. else
  6838. {
  6839. return $r;
  6840. }
  6841. }
  6842. /* END */
  6843. /** -----------------------------------------
  6844. /** Save ping servers
  6845. /** -----------------------------------------*/
  6846. function save_ping_servers()
  6847. {
  6848. global $IN, $FNS, $LANG, $DB, $DSP, $PREFS;
  6849. $id = $IN->GBL('member_id');
  6850. if ($id == 0 AND ! $DSP->allowed_group('can_admin_weblogs'))
  6851. {
  6852. return $DSP->no_access_message();
  6853. }
  6854. if ( ! is_numeric($id))
  6855. {
  6856. return FALSE;
  6857. }
  6858. $data = array();
  6859. foreach ($_POST as $key => $val)
  6860. {
  6861. if (strstr($key, 'server_name_') AND $val != '')
  6862. {
  6863. $n = substr($key, 12);
  6864. $data[] = array(
  6865. 'member_id' => $id,
  6866. 'server_name' => $_POST['server_name_'.$n],
  6867. 'server_url' => $_POST['server_url_'.$n],
  6868. 'port' => $_POST['server_port_'.$n],
  6869. 'ping_protocol' => $_POST['ping_protocol_'.$n],
  6870. 'is_default' => $_POST['is_default_'.$n],
  6871. 'server_order' => $_POST['server_order_'.$n],
  6872. 'site_id' => $PREFS->ini('site_id')
  6873. );
  6874. }
  6875. }
  6876. $DB->query("DELETE FROM exp_ping_servers WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND member_id = '$id'");
  6877. foreach ($data as $val)
  6878. {
  6879. $DB->query($DB->insert_string('exp_ping_servers', $val));
  6880. }
  6881. $message = $DSP->qdiv('success', $LANG->line('preferences_updated'));
  6882. if ($id == 0)
  6883. {
  6884. $this->ping_servers($message);
  6885. }
  6886. else
  6887. {
  6888. $FNS->redirect(BASE.AMP.'C=myaccount'.AMP.'M=pingservers'.AMP.'id='.$id.AMP.'U=1');
  6889. exit;
  6890. }
  6891. }
  6892. /* END */
  6893. /** -----------------------------------------------------------
  6894. /** File Upload Preferences Page
  6895. /** -----------------------------------------------------------*/
  6896. function file_upload_preferences($update = '')
  6897. {
  6898. global $DSP, $IN, $DB, $LANG, $PREFS;
  6899. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  6900. {
  6901. return $DSP->no_access_message();
  6902. }
  6903. $r = '';
  6904. if ($update != '')
  6905. {
  6906. $r .= $DSP->qdiv('box', $DSP->qdiv('success', $LANG->line('preferences_updated')));
  6907. }
  6908. $r .= $DSP->table('tableBorder', '0', '10', '100%').
  6909. $DSP->tr().
  6910. $DSP->td('tableHeading', '', '3').
  6911. $LANG->line('current_upload_prefs').
  6912. $DSP->td_c().
  6913. $DSP->tr_c();
  6914. $query = $DB->query("SELECT * FROM exp_upload_prefs WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND is_user_blog = 'n' ORDER BY name");
  6915. if ($query->num_rows == 0)
  6916. {
  6917. $r .= $DSP->tr().
  6918. $DSP->td('tableCellTwo', '', '3').
  6919. '<b>'.$LANG->line('no_upload_prefs').'</b>'.
  6920. $DSP->td_c().
  6921. $DSP->tr_c();
  6922. }
  6923. $i = 0;
  6924. if ($query->num_rows > 0)
  6925. {
  6926. foreach ($query->result as $row)
  6927. {
  6928. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  6929. $r .= $DSP->tr();
  6930. $r .= $DSP->table_qcell($style, $i.$DSP->nbs(2).$DSP->qspan('defaultBold', $row['name']), '40%');
  6931. $r .= $DSP->table_qcell($style, $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=edit_upload_pref'.AMP.'id='.$row['id'], $LANG->line('edit')), '30%');
  6932. $r .= $DSP->table_qcell($style, $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=del_upload_pref_conf'.AMP.'id='.$row['id'], $LANG->line('delete')), '30%');
  6933. $r .= $DSP->tr_c();
  6934. }
  6935. }
  6936. $r .= $DSP->table_c();
  6937. $DSP->title = $LANG->line('file_upload_preferences');
  6938. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  6939. $DSP->crumb_item($LANG->line('file_upload_preferences'));
  6940. $DSP->right_crumb($LANG->line('create_new_upload_pref'), BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=edit_upload_pref');
  6941. $DSP->body = $r;
  6942. }
  6943. /* END */
  6944. /** --------------------------------------
  6945. /** New/Edit Upload Preferences form
  6946. /** --------------------------------------*/
  6947. function edit_upload_preferences_form()
  6948. {
  6949. global $DSP, $IN, $DB, $LANG, $PREFS;
  6950. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  6951. {
  6952. return $DSP->no_access_message();
  6953. }
  6954. $id = $IN->GBL('id');
  6955. $type = ($id !== FALSE) ? 'edit' : 'new';
  6956. $DB->fetch_fields = TRUE;
  6957. $query = $DB->query("SELECT * FROM exp_upload_prefs WHERE id = '$id' AND is_user_blog = 'n'");
  6958. if ($query->num_rows == 0)
  6959. {
  6960. if ($id != '')
  6961. return $DSP->no_access_message();
  6962. foreach ($query->fields as $f)
  6963. {
  6964. $$f = '';
  6965. }
  6966. }
  6967. else
  6968. {
  6969. foreach ($query->row as $key => $val)
  6970. {
  6971. $$key = $val;
  6972. }
  6973. }
  6974. // Form declaration
  6975. $r = $DSP->form_open(array('action' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=update_upload_prefs'));
  6976. $r .= $DSP->input_hidden('id', $id);
  6977. $r .= $DSP->input_hidden('cur_name', $name);
  6978. $r .= $DSP->table('tableBorder', '0', '', '100%').
  6979. $DSP->td('tableHeading', '', '2');
  6980. if ($type == 'edit')
  6981. $r .= $LANG->line('edit_file_upload_preferences');
  6982. else
  6983. $r .= $LANG->line('new_file_upload_preferences');
  6984. $r .= $DSP->td_c().
  6985. $DSP->tr_c();
  6986. $i = 0;
  6987. $s1 = 'tableCellOne';
  6988. $s2 = 'tableCellTwo';
  6989. $r .= $DSP->table_qrow( ($i++ % 2) ? $s1 : $s2,
  6990. array(
  6991. $DSP->qspan('defaultBold', $DSP->required().NBS.$LANG->line('upload_pref_name', 'upload_pref_name')),
  6992. $DSP->input_text('name', $name, '50', '50', 'input', '100%')
  6993. )
  6994. );
  6995. $r .= $DSP->table_qrow( ($i++ % 2) ? $s1 : $s2,
  6996. array(
  6997. $DSP->qspan('defaultBold', $DSP->required().NBS.$LANG->line('server_path', 'server_path')),
  6998. $DSP->input_text('server_path', $server_path, '50', '100', 'input', '100%')
  6999. )
  7000. );
  7001. if ($url == '')
  7002. $url = 'http://';
  7003. $r .= $DSP->table_qrow( ($i++ % 2) ? $s1 : $s2,
  7004. array(
  7005. $DSP->qspan('defaultBold', $DSP->required().NBS.$LANG->line('url_to_upload_dir', 'url_to_upload_dir')),
  7006. $DSP->input_text('url', $url, '50', '100', 'input', '100%')
  7007. )
  7008. );
  7009. if ($allowed_types == '')
  7010. $allowed_types = 'img';
  7011. $r .= $DSP->table_qrow( ($i++ % 2) ? $s1 : $s2,
  7012. array(
  7013. $DSP->qspan('defaultBold', $DSP->required().NBS.$LANG->line('allowed_types', 'allowed_types')),
  7014. $DSP->input_radio('allowed_types', 'img', ($allowed_types == 'img') ? 1 : '').NBS.$LANG->line('images_only')
  7015. .NBS.NBS.NBS.$DSP->input_radio('allowed_types', 'all', ($allowed_types == 'all') ? 1 : '').NBS.$LANG->line('all_filetypes')
  7016. )
  7017. );
  7018. $r .= $DSP->table_qrow( ($i++ % 2) ? $s1 : $s2,
  7019. array(
  7020. $DSP->qspan('defaultBold', $LANG->line('max_size', 'max_size')),
  7021. $DSP->input_text('max_size', $max_size, '15', '16', 'input', '90px')
  7022. )
  7023. );
  7024. $r .= $DSP->table_qrow( ($i++ % 2) ? $s1 : $s2,
  7025. array(
  7026. $DSP->qspan('defaultBold', $LANG->line('max_height', 'max_height')),
  7027. $DSP->input_text('max_height', $max_height, '10', '6', 'input', '60px')
  7028. )
  7029. );
  7030. $r .= $DSP->table_qrow( ($i++ % 2) ? $s1 : $s2,
  7031. array(
  7032. $DSP->qspan('defaultBold', $LANG->line('max_width', 'max_width')),
  7033. $DSP->input_text('max_width', $max_width, '10', '6', 'input', '60px')
  7034. )
  7035. );
  7036. $r .= $DSP->table_qrow( ($i++ % 2) ? $s1 : $s2,
  7037. array(
  7038. $DSP->qspan('defaultBold', $LANG->line('properties', 'properties')),
  7039. $DSP->input_text('properties', $properties, '50', '120', 'input', '100%')
  7040. )
  7041. );
  7042. $r .= $DSP->table_qrow( ($i++ % 2) ? $s1 : $s2,
  7043. array(
  7044. $DSP->qspan('defaultBold', $LANG->line('pre_format', 'pre_format')),
  7045. $DSP->input_text('pre_format', $pre_format, '50', '120', 'input', '100%')
  7046. )
  7047. );
  7048. $r .= $DSP->table_qrow( ($i++ % 2) ? $s1 : $s2,
  7049. array(
  7050. $DSP->qspan('defaultBold', $LANG->line('post_format', 'post_format')),
  7051. $DSP->input_text('post_format', $post_format, '50', '120', 'input', '100%')
  7052. )
  7053. );
  7054. $r .= $DSP->table_qrow( ($i++ % 2) ? $s1 : $s2,
  7055. array(
  7056. $DSP->qspan('defaultBold', $LANG->line('file_properties', 'file_properties')),
  7057. $DSP->input_text('file_properties', $file_properties, '50', '120', 'input', '100%')
  7058. )
  7059. );
  7060. $r .= $DSP->table_qrow( ($i++ % 2) ? $s1 : $s2,
  7061. array(
  7062. $DSP->qspan('defaultBold', $LANG->line('file_pre_format', 'file_pre_format')),
  7063. $DSP->input_text('file_pre_format', $file_pre_format, '50', '120', 'input', '100%')
  7064. )
  7065. );
  7066. $r .= $DSP->table_qrow( ($i++ % 2) ? $s1 : $s2,
  7067. array(
  7068. $DSP->qspan('defaultBold', $LANG->line('file_post_format', 'file_post_format')),
  7069. $DSP->input_text('file_post_format', $file_post_format, '50', '120', 'input', '100%')
  7070. )
  7071. );
  7072. $r .= $DSP->table_c();
  7073. $r .= $DSP->qdiv('itemWrapperTop', $DSP->heading($LANG->line('restrict_to_group'), 5).$LANG->line('restrict_notes_1').$DSP->qdiv('itemWrapper', $DSP->qdiv('highlight', $LANG->line('restrict_notes_2'))));
  7074. $query = $DB->query("SELECT group_id, group_title FROM exp_member_groups WHERE group_id != '1' AND group_id != '2' AND group_id != '3' AND group_id != '4' AND site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' ORDER BY group_title");
  7075. if ($query->num_rows > 0)
  7076. {
  7077. $r .= $DSP->table('tableBorder', '0', '', '100%').
  7078. $DSP->tr().
  7079. $DSP->td('tableHeading', '', '').
  7080. $LANG->line('member_group').
  7081. $DSP->td_c().
  7082. $DSP->td('tableHeading', '', '').
  7083. $LANG->line('can_upload_files').
  7084. $DSP->td_c().
  7085. $DSP->tr_c();
  7086. $i = 0;
  7087. $group = array();
  7088. $sql = "SELECT member_group FROM exp_upload_no_access ";
  7089. if ($id != '')
  7090. {
  7091. $sql .= "WHERE upload_id = '$id'";
  7092. }
  7093. $result = $DB->query($sql);
  7094. if ($result->num_rows != 0)
  7095. {
  7096. foreach($result->result as $row)
  7097. {
  7098. $group[$row['member_group']] = TRUE;
  7099. }
  7100. }
  7101. foreach ($query->result as $row)
  7102. {
  7103. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  7104. $r .= $DSP->tr().
  7105. $DSP->td($style, '50%').
  7106. $row['group_title'].
  7107. $DSP->td_c().
  7108. $DSP->td($style, '50%');
  7109. $selected = ( ! isset($group[$row['group_id']])) ? 1 : '';
  7110. $r .= $LANG->line('yes').NBS.
  7111. $DSP->input_radio('access_'.$row['group_id'], 'y', $selected).$DSP->nbs(3);
  7112. $selected = (isset($group[$row['group_id']])) ? 1 : '';
  7113. $r .= $LANG->line('no').NBS.
  7114. $DSP->input_radio('access_'.$row['group_id'], 'n', $selected).$DSP->nbs(3);
  7115. $r .= $DSP->td_c()
  7116. .$DSP->tr_c();
  7117. }
  7118. $r .= $DSP->table_c();
  7119. }
  7120. $r .= $DSP->div('itemWrapper')
  7121. .$DSP->qdiv('itemWrapper', $DSP->required(1));
  7122. if ($type == 'edit')
  7123. $r .= $DSP->input_submit($LANG->line('update'));
  7124. else
  7125. $r .= $DSP->input_submit($LANG->line('submit'));
  7126. $r .= $DSP->div_c();
  7127. $r .= $DSP->form_close();
  7128. $lang_line = ($type == 'edit') ? 'edit_file_upload_preferences' : 'create_new_upload_pref';
  7129. $DSP->title = $LANG->line($lang_line);
  7130. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  7131. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=upload_prefs', $LANG->line('file_upload_prefs'))).
  7132. $DSP->crumb_item($LANG->line($lang_line));
  7133. $DSP->body = $r;
  7134. }
  7135. /* END */
  7136. /** ------------------------------------
  7137. /** Update upload preferences
  7138. /** ------------------------------------*/
  7139. function update_upload_preferences()
  7140. {
  7141. global $DSP, $IN, $DB, $LANG, $FNS, $PREFS;
  7142. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  7143. {
  7144. return $DSP->no_access_message();
  7145. }
  7146. // If the $id variable is present we are editing an
  7147. // existing field, otherwise we are creating a new one
  7148. $edit = (isset($_POST['id']) AND $_POST['id'] != '' && is_numeric($_POST['id'])) ? TRUE : FALSE;
  7149. // Check for required fields
  7150. $error = array();
  7151. if ($_POST['name'] == '')
  7152. {
  7153. $error[] = $LANG->line('no_upload_dir_name');
  7154. }
  7155. if ($_POST['server_path'] == '')
  7156. {
  7157. $error[] = $LANG->line('no_upload_dir_path');
  7158. }
  7159. if ($_POST['url'] == '' OR $_POST['url'] == 'http://')
  7160. {
  7161. $error[] = $LANG->line('no_upload_dir_url');
  7162. }
  7163. if (substr($_POST['server_path'], -1) != '/' AND substr($_POST['server_path'], -1) != '\\')
  7164. {
  7165. $_POST['server_path'] .= '/';
  7166. }
  7167. $_POST['url'] = rtrim($_POST['url'], '/').'/';
  7168. // Is the name taken?
  7169. $sql = "SELECT count(*) as count FROM exp_upload_prefs WHERE site_id = '".$DB->escape_str($PREFS->ini('site_id'))."' AND name = '".$DB->escape_str($_POST['name'])."'";
  7170. $query = $DB->query($sql);
  7171. if (($edit == FALSE || ($edit == TRUE && strtolower($_POST['name']) != strtolower($_POST['cur_name']))) && $query->row['count'] > 0)
  7172. {
  7173. $error[] = $LANG->line('duplicate_dir_name');
  7174. }
  7175. // Are there errors to display?
  7176. if (count($error) > 0)
  7177. {
  7178. $str = '';
  7179. foreach ($error as $msg)
  7180. {
  7181. $str .= $msg.BR;
  7182. }
  7183. return $DSP->error_message($str);
  7184. }
  7185. $id = $IN->GBL('id');
  7186. unset($_POST['id']);
  7187. unset($_POST['cur_name']);
  7188. $data = array();
  7189. $no_access = array();
  7190. $DB->query("DELETE FROM exp_upload_no_access WHERE upload_id = '$id'");
  7191. foreach ($_POST as $key => $val)
  7192. {
  7193. if (substr($key, 0, 7) == 'access_')
  7194. {
  7195. if ($val == 'n')
  7196. {
  7197. $no_access[] = substr($key, 7);
  7198. }
  7199. }
  7200. else
  7201. {
  7202. $data[$key] = $val;
  7203. }
  7204. }
  7205. // Construct the query based on whether we are updating or inserting
  7206. if ($edit === TRUE)
  7207. {
  7208. $DB->query($DB->update_string('exp_upload_prefs', $data, 'id='.$id));
  7209. }
  7210. else
  7211. {
  7212. $data['site_id'] = $PREFS->ini('site_id');
  7213. $DB->query($DB->insert_string('exp_upload_prefs', $data));
  7214. $id = $DB->insert_id;
  7215. }
  7216. if (sizeof($no_access) > 0)
  7217. {
  7218. foreach($no_access as $member_group)
  7219. {
  7220. $DB->query("INSERT INTO exp_upload_no_access (upload_id, upload_loc, member_group) VALUES ('$id', 'cp', '".$DB->escape_str($member_group)."')");
  7221. }
  7222. }
  7223. // Clear database cache
  7224. $FNS->clear_caching('db');
  7225. return $this->file_upload_preferences(1);
  7226. }
  7227. /* END */
  7228. /** --------------------------------------
  7229. /** Upload preferences delete confirm
  7230. /** --------------------------------------*/
  7231. function delete_upload_preferences_conf()
  7232. {
  7233. global $DSP, $IN, $DB, $LANG;
  7234. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  7235. {
  7236. return $DSP->no_access_message();
  7237. }
  7238. if ( ! $id = $IN->GBL('id'))
  7239. {
  7240. return FALSE;
  7241. }
  7242. if ( ! is_numeric($id))
  7243. {
  7244. return FALSE;
  7245. }
  7246. $query = $DB->query("SELECT name FROM exp_upload_prefs WHERE id = '$id'");
  7247. $DSP->title = $LANG->line('delete_upload_preference');
  7248. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=weblog_administration', $LANG->line('weblog_administration')).
  7249. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=blog_admin'.AMP.'P=upload_prefs', $LANG->line('file_upload_prefs'))).
  7250. $DSP->crumb_item($LANG->line('delete_upload_preference'));
  7251. $DSP->body = $DSP->delete_confirmation(
  7252. array(
  7253. 'url' => 'C=admin'.AMP.'M=blog_admin'.AMP.'P=del_upload_pref'.AMP.'id='.$id,
  7254. 'heading' => 'delete_upload_preference',
  7255. 'message' => 'delete_upload_pref_confirmation',
  7256. 'item' => $query->row['name'],
  7257. 'extra' => '',
  7258. 'hidden' => array('id', $id)
  7259. )
  7260. );
  7261. }
  7262. /* END */
  7263. /** --------------------------------------
  7264. /** Delete upload preferences
  7265. /** --------------------------------------*/
  7266. function delete_upload_preferences()
  7267. {
  7268. global $DSP, $IN, $DB, $LOG, $FNS, $LANG;
  7269. if ( ! $DSP->allowed_group('can_admin_weblogs'))
  7270. {
  7271. return $DSP->no_access_message();
  7272. }
  7273. if ( ! $id = $IN->GBL('id'))
  7274. {
  7275. return FALSE;
  7276. }
  7277. if ( ! is_numeric($id))
  7278. {
  7279. return FALSE;
  7280. }
  7281. $DB->query("DELETE FROM exp_upload_no_access WHERE upload_id = '$id'");
  7282. $query = $DB->query("SELECT name FROM exp_upload_prefs WHERE id = '$id'");
  7283. $name = $query->row['name'];
  7284. $DB->query("DELETE FROM exp_upload_prefs WHERE id = '$id'");
  7285. $LOG->log_action($LANG->line('upload_pref_deleted').$DSP->nbs(2).$name);
  7286. // Clear database cache
  7287. $FNS->clear_caching('db');
  7288. return $this->file_upload_preferences();
  7289. }
  7290. /* END */
  7291. }
  7292. // END CLASS
  7293. ?>