/** * Interface to import/export. * * @return tempcode The interface. */ function ui() { $title = get_page_title('XML_DATA_MANAGEMENT'); require_code('form_templates'); $import_url = build_url(array('page' => '_SELF', 'type' => '_import'), '_SELF'); $import_fields = new ocp_tempcode(); $import_fields->attach(form_input_huge(do_lang_tempcode('XML_DATA'), '', 'xml', '', true)); $import_form = do_template('FORM', array('TABINDEX' => strval(get_form_field_tabindex()), 'URL' => $import_url, 'HIDDEN' => '', 'TEXT' => do_lang_tempcode('XML_IMPORT_TEXT'), 'FIELDS' => $import_fields, 'SUBMIT_NAME' => do_lang_tempcode('IMPORT'))); $all_tables = find_all_xml_tables(); $export_url = build_url(array('page' => '_SELF', 'type' => '_export'), '_SELF'); $export_fields = new ocp_tempcode(); $nice_tables = new ocp_tempcode(); foreach ($all_tables as $table) { $nice_tables->attach(form_input_list_entry($table)); } $export_fields->attach(form_input_multi_list(do_lang_tempcode('TABLES'), do_lang_tempcode('DESCRIPTION_TABLES'), 'tables', $nice_tables, NULL, 15)); $export_fields->attach(form_input_tick(do_lang_tempcode('EXPORT_WITH_COMCODE_XML'), do_lang_tempcode('DESCRIPTION_EXPORT_WITH_COMCODE_XML'), 'comcode_xml', false)); $export_form = do_template('FORM', array('TABINDEX' => strval(get_form_field_tabindex()), 'URL' => $export_url, 'HIDDEN' => '', 'TEXT' => do_lang_tempcode('XML_EXPORT_TEXT'), 'FIELDS' => $export_fields, 'SUBMIT_NAME' => do_lang_tempcode('EXPORT'))); return do_template('XML_STORAGE_SCREEN', array('TITLE' => $title, 'IMPORT_FORM' => $import_form, 'EXPORT_FORM' => $export_form)); }
/** * The UI to send a newsletter. * * @param LONG_TEXT Default newsletter to put in * @return tempcode The UI */ function send_gui($_existing = '') { // If this is a periodic newsletter, we make some changes to the regular // language strings. $periodic_action_raw = post_param('periodic_choice', ''); $periodic_subject = ''; $defaults = mixed(); switch (preg_replace('#\\_\\d+$#', '', $periodic_action_raw)) { case 'remove_existing': // Remove whatever is already set. We don't need any changes for // this, but we do need a hidden form field. $periodic_action = 'remove'; break; case 'replace_existing': // Make the current newsletter periodic. This requires language // fiddling. $periodic_action = 'replace'; $periodic_subject = do_lang('PERIODIC_SUBJECT_HELP'); $periodic_id = intval(preg_replace('#^[^\\d]+#', '', $periodic_action_raw)); $_defaults = $GLOBALS['SITE_DB']->query_select('newsletter_periodic', array('*'), array('id' => $periodic_id), '', 1); if (!array_key_exists(0, $_defaults)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $defaults = $_defaults[0]; break; case 'make_periodic': // Make the current newsletter periodic. This requires language // fiddling. $periodic_action = 'make'; $periodic_subject = do_lang('PERIODIC_SUBJECT_HELP'); break; case 'no_change': default: // The default action is to leave the current settings as-is. $periodic_action = 'none'; break; } $title = get_page_title('NEWSLETTER_SEND'); $lang = choose_language($title); if (is_object($lang)) { return $lang; } $comcode_given = $_existing != '' && strpos($_existing, '<html') !== false; $_existing = post_param('message', $_existing); if ($_existing == '') { $from_news = get_param_integer('from_news', -1); if ($from_news != -1 && addon_installed('news')) { $rows = $GLOBALS['SITE_DB']->query_select('news', array('*'), array('id' => $from_news), 'ORDER BY id DESC', 1); if (!array_key_exists(0, $rows)) { require_lang('news'); return warn_screen(get_page_title('NEWS'), do_lang_tempcode('MISSING_RESOURCE')); } $myrow = $rows[0]; $_existing = get_translated_text($myrow['news_article'], NULL, $lang); if ($_existing == '') { $_existing = get_translated_text($myrow['news'], NULL, $lang); } } $existing = do_template('NEWSLETTER_DEFAULT', array('_GUID' => '53c02947915806e519fe14c318813f42', 'CONTENT' => $_existing, 'LANG' => $lang)); } else { $default = do_template('NEWSLETTER_DEFAULT', array('_GUID' => '53c02947915806e519fe14c318813f44', 'CONTENT' => $_existing, 'LANG' => $lang)); if (strpos($default->evaluate(), '<html') !== false) { if ($comcode_given) { $default = do_template('NEWSLETTER_DEFAULT', array('_GUID' => '53c02947915806e519fe14c318813f46', 'CONTENT' => comcode_to_tempcode($_existing), 'LANG' => $lang)); } $existing = $default; } else { $existing = make_string_tempcode($_existing); } } $post_url = build_url(array('page' => '_SELF', 'type' => 'confirm', 'old_type' => get_param('type', '')), '_SELF'); $submit_name = do_lang_tempcode('PREVIEW'); $hidden = new ocp_tempcode(); $hidden->attach(form_input_hidden('lang', $lang)); // Build up form $fields = new ocp_tempcode(); require_code('form_templates'); $default_subject = get_option('newsletter_title'); if (!is_null($defaults)) { $default_subject = $defaults['np_subject']; } if ($periodic_action != 'make' && $periodic_action != 'replace') { $default_subject .= ' - ' . get_timezoned_date(time(), false, false, false, true); } $default_subject = post_param('subject', $default_subject); $fields->attach(form_input_line_comcode(do_lang_tempcode('SUBJECT'), do_lang_tempcode('NEWSLETTER_DESCRIPTION_TITLE', $periodic_subject), 'subject', $default_subject, true)); $in_full = post_param_integer('in_full', 0); $chosen_categories = post_param('chosen_categories', ''); if ($periodic_action == 'make' || $periodic_action == 'replace') { // We are making a periodic newsletter. This means we need to pass // through the chosen categories if (!is_null($defaults)) { $chosen_categories = $defaults['np_message']; $in_full = $defaults['np_in_full']; $fields->attach(form_input_tick(do_lang_tempcode('EMBED_FULL_ARTICLES'), do_lang_tempcode('DESCRIPTION_EMBED_FULL_ARTICLES'), 'in_full', $in_full == 1)); $fields->attach(form_input_huge(do_lang_tempcode('NEWSLETTER_CONTENT'), do_lang('NEWSLETTER_CONTENT_SELECT'), 'chosen_categories', $chosen_categories, true)); } else { $hidden->attach(form_input_hidden('chosen_categories', $chosen_categories)); $hidden->attach(form_input_hidden('in_full', strval($in_full))); } $hidden->attach(form_input_hidden('cutoff_day', post_param('cutoff_day'))); $hidden->attach(form_input_hidden('cutoff_month', post_param('cutoff_month'))); $hidden->attach(form_input_hidden('cutoff_year', post_param('cutoff_year'))); $hidden->attach(form_input_hidden('cutoff_hour', post_param('cutoff_hour'))); $hidden->attach(form_input_hidden('cutoff_minute', post_param('cutoff_minute'))); $hidden->attach(form_input_hidden('message', $existing->evaluate())); } else { $hidden->attach(form_input_hidden('in_full', strval($in_full))); if (strpos($existing->evaluate(), '<html') === false) { $fields->attach(form_input_huge_comcode(do_lang_tempcode('MESSAGE'), do_lang_tempcode('DESCRIPTION_MESSAGE_NEWSLETTER'), 'message', $existing->evaluate(), true)); } else { $fields->attach(form_input_huge(do_lang_tempcode('MESSAGE'), do_lang_tempcode('DESCRIPTION_MESSAGE_NEWSLETTER'), 'message', $existing->evaluate(), true)); } } if (addon_installed('calendar') && $periodic_action == 'none' && cron_installed()) { $fields->attach(form_input_date__scheduler(do_lang_tempcode('DEFER_TIME'), do_lang_tempcode('DESCRIPTION_DEFER_TIME'), 'schedule', true, true, true)); } $from_email = post_param('from_email', get_option('staff_address')); if (!is_null($defaults)) { $from_email = post_param('from_email', $defaults['np_from_email']); } $fields->attach(form_input_email(do_lang_tempcode('FROM_EMAIL'), do_lang_tempcode('DESCRIPTION_NEWSLETTER_FROM_EMAIL'), 'from_email', $from_email, true)); $from_name = post_param('from_name', get_site_name()); if (!is_null($defaults)) { $from_name = post_param('from_name', $defaults['np_from_name']); } $fields->attach(form_input_line(do_lang_tempcode('FROM_NAME'), do_lang_tempcode('DESCRIPTION_NEWSLETTER_FROM_NAME'), 'from_name', $from_name, true)); $_html_only = post_param_integer('html_only', NULL); if (is_null($_html_only)) { $html_only = strpos($existing->evaluate(), '<html') !== false; if (!is_null($defaults)) { $html_only = $defaults['np_html_only']; } } else { $html_only = $_html_only == 1; } if (get_value('force_html_only') === '1') { $hidden->attach(form_input_hidden('html_only', '1')); } else { $fields->attach(form_input_tick(do_lang_tempcode('HTML_ONLY'), do_lang_tempcode('DESCRIPTION_HTML_ONLY'), 'html_only', $html_only)); } $l = new ocp_tempcode(); $priority = post_param_integer('priority', 3); if (!is_null($defaults)) { $priority = post_param_integer('priority', $defaults['np_priority']); } for ($i = 1; $i <= 5; $i++) { $l->attach(form_input_list_entry(strval($i), $i == $priority, do_lang_tempcode('PRIORITY_' . strval($i)))); } $fields->attach(form_input_list(do_lang_tempcode('PRIORITY'), do_lang_tempcode('DESCRIPTION_NEWSLETTER_PRIORITY'), 'priority', $l)); // Where to send to $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('CHOOSE_SEND_TO')))); $newsletters = $GLOBALS['SITE_DB']->query_select('newsletters', array('*')); foreach ($newsletters as $newsletter) { $level = post_param_integer(strval($newsletter['id']), post_param_integer('level', -1)); $c4 = $this->count_level($newsletter['id'], 4, $lang); $c3 = $this->count_level($newsletter['id'], 3, $lang); $c2 = $this->count_level($newsletter['id'], 2, $lang); $c1 = $this->count_level($newsletter['id'], 1, $lang); if ($c1 != 0) { $newsletter_title = get_translated_text($newsletter['title']); $newsletter_description = get_translated_text($newsletter['description']); if ($c1 == $c2 && $c1 == $c3 && $c1 == $c4) { $fields->attach(form_input_tick(do_lang_tempcode('NEWSLETTER_PREFIX', escape_html($newsletter_title)), do_lang_tempcode('DESCRIPTION_NOSUBSCRIPTION_LEVEL', escape_html(integer_format($c4)), escape_html($newsletter_description)), strval($newsletter['id']), $level >= 1, NULL, '4')); } else { $l = new ocp_tempcode(); $l->attach(form_input_list_entry('0', $level == 0, do_lang_tempcode('NNR', do_lang_tempcode('NEWSLETTER_0_ALT'), do_lang_tempcode('NUM_READERS', integer_format(0))))); $l->attach(form_input_list_entry('1', $level == 1, do_lang_tempcode('NNR', do_lang_tempcode('NEWSLETTER_1'), do_lang_tempcode('NUM_READERS', integer_format($c1))))); $l->attach(form_input_list_entry('2', $level == 2, do_lang_tempcode('NNR', do_lang_tempcode('NEWSLETTER_2'), do_lang_tempcode('NUM_READERS', integer_format($c2))))); $l->attach(form_input_list_entry('3', $level == 3, do_lang_tempcode('NNR', do_lang_tempcode('NEWSLETTER_3'), do_lang_tempcode('NUM_READERS', integer_format($c3))))); $l->attach(form_input_list_entry('4', $level == 4, do_lang_tempcode('NNR', do_lang_tempcode('NEWSLETTER_4'), do_lang_tempcode('NUM_READERS', integer_format($c4))))); $fields->attach(form_input_list(do_lang_tempcode('SUBSCRIPTION_LEVEL_FOR', escape_html($newsletter_title)), do_lang_tempcode('DESCRIPTION_SUBSCRIPTION_LEVEL', escape_html($newsletter_description)), strval($newsletter['id']), $l)); } } } if (get_forum_type() == 'ocf') { $c5 = $this->count_level(-1, 5, $lang); $fields->attach(form_input_tick(do_lang_tempcode('NEWSLETTER_OCF'), do_lang_tempcode('NUM_READERS', integer_format($c5)), '-1', false)); $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(); foreach ($groups as $group_id => $group) { if ($group_id != db_get_first_id()) { $map = array(); $map['g' . strval($group_id)] = 1; $_c = newsletter_who_send_to($map, $lang, 0, 0); $c6 = $_c[6]['g' . strval($group_id)]; if ($c6 != 0) { $fields->attach(form_input_tick(do_lang_tempcode('THIS_WITH', do_lang_tempcode('GROUP'), make_string_tempcode(escape_html($group))), do_lang_tempcode('NUM_READERS', integer_format($c6)), 'g' . strval($group_id), post_param_integer('g' . strval($group_id), 0) == 1)); } } } } $fields->attach(form_input_upload(do_lang_tempcode('UPLOAD'), do_lang_tempcode('DESCRIPTION_UPLOAD_CSV'), 'file', false, NULL, NULL, true, 'csv,txt')); //if ($fields->is_empty()) inform_exit(do_lang_tempcode('NOBODY_TO_SEND_TO')); handle_max_file_size($hidden); $template_choices = new ocp_tempcode(); $dh = opendir(get_custom_file_base() . '/themes/default/templates_custom'); while (($f = readdir($dh)) !== false) { if (preg_match('#^MAIL.*\\.tpl$#', $f) != 0) { $tpl = basename($f, '.tpl'); $template_choices->attach(form_input_list_entry($tpl, post_param('template', 'MAIL') == $tpl, $tpl)); } } if (!file_exists(get_custom_file_base() . '/themes/default/templates_custom/MAIL.tpl')) { $template_choices->attach(form_input_list_entry('MAIL', true, 'MAIL')); } closedir($dh); $fields->attach(form_input_list(do_lang_tempcode('NEWSLETTER_TEMPLATE'), do_lang_tempcode('DESCRIPTION_NEWSLETTER_TEMPLATE'), 'template', $template_choices, NULL, false, true)); // If we're making a periodic newsletter then we need to know when it // should be sent if ($periodic_action == 'make' || $periodic_action == 'replace') { $hidden->attach(form_input_hidden('make_periodic', '1')); $hidden->attach(form_input_hidden('periodic_choice', post_param('periodic_choice'))); $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang('PERIODIC_WHEN'), 'HELP' => do_lang('PERIODIC_WHEN_HELP')))); // The choices are given as radio buttons: weekly or bi-weekly or monthly? // In the labels for these radio buttons, we put a dropdown for day of // the week and day of the month. $frequency = post_param('periodic_when', 'weekly'); if (!is_null($defaults)) { $frequency = post_param('periodic_when', $defaults['np_frequency']); } $current_day_weekly = post_param_integer('periodic_weekly', 5); if (!is_null($defaults)) { $current_day_weekly = post_param_integer('periodic_weekly', $defaults['np_day']); } $current_day_biweekly = post_param_integer('periodic_biweekly', 5); if (!is_null($defaults)) { $current_day_biweekly = post_param_integer('periodic_biweekly', $defaults['np_day']); } $current_day_of_month = post_param_integer('periodic_monthly', 1); if (!is_null($defaults)) { $current_day_of_month = post_param_integer('periodic_monthly', $defaults['np_day']); } $radios = new ocp_tempcode(); $week_days_weekly = new ocp_tempcode(); $week_days_biweekly = new ocp_tempcode(); require_lang('dates'); $week_days = array(1 => do_lang('MONDAY'), 2 => do_lang('TUESDAY'), 3 => do_lang('WEDNESDAY'), 4 => do_lang('THURSDAY'), 5 => do_lang('FRIDAY'), 6 => do_lang('SATURDAY'), 7 => do_lang('SUNDAY')); foreach ($week_days as $i => $this_day) { $week_days_weekly->attach(form_input_list_entry(strval($i), $i == $current_day_weekly, $this_day, false, false)); $week_days_biweekly->attach(form_input_list_entry(strval($i), $i == $current_day_biweekly, $this_day, false, false)); } $weekly_desc = new ocp_tempcode(); $weekly_desc->attach(do_lang('PERIODIC_WEEKLY_ON')); $weekly_desc->attach(do_template('FORM_SCREEN_INPUT_LIST', array('TABINDEX' => strval(get_form_field_tabindex(NULL)), 'REQUIRED' => '0', 'NAME' => 'periodic_weekday_weekly', 'CONTENT' => $week_days_weekly, 'INLINE_LIST' => '0'))); $radios->attach(form_input_radio_entry('periodic_when', 'weekly', $frequency == 'weekly', $weekly_desc, NULL, '')); $weekly_desc = new ocp_tempcode(); $weekly_desc->attach(do_lang('PERIODIC_BIWEEKLY_ON')); $weekly_desc->attach(do_template('FORM_SCREEN_INPUT_LIST', array('TABINDEX' => strval(get_form_field_tabindex(NULL)), 'REQUIRED' => '0', 'NAME' => 'periodic_weekday_biweekly', 'CONTENT' => $week_days_biweekly, 'INLINE_LIST' => '0'))); $radios->attach(form_input_radio_entry('periodic_when', 'biweekly', $frequency == 'biweekly', $weekly_desc, NULL, '')); $month_days = new ocp_tempcode(); foreach (range(1, 28) as $this_day) { $suffix = gmdate('S', gmmktime(0, 0, 0, 1, $this_day, 1990)); $month_days->attach(form_input_list_entry(strval($this_day), $this_day == 1, strval($this_day) . $suffix, $current_day_of_month == $this_day)); } $monthly_desc = new ocp_tempcode(); $monthly_desc->attach(do_lang('PERIODIC_MONTHLY_ON')); $monthly_desc->attach(do_template('FORM_SCREEN_INPUT_LIST', array('TABINDEX' => strval(get_form_field_tabindex(NULL)), 'REQUIRED' => '0', 'NAME' => 'periodic_monthly', 'CONTENT' => $month_days, 'INLINE_LIST' => '0'))); $radios->attach(form_input_radio_entry('periodic_when', 'monthly', $frequency == 'monthly', $monthly_desc, NULL, '')); $fields->attach(form_input_radio(do_lang('PERIODIC_WHEN_CHOICE'), '', 'periodic_when', $radios, true)); $radios = new ocp_tempcode(); $radios->attach(form_input_radio_entry('periodic_for', 'all', false, do_lang_tempcode('CREATE_PERIODIC_FOR_ALL'), NULL, '')); $radios->attach(form_input_radio_entry('periodic_for', 'future', true, do_lang_tempcode('CREATE_PERIODIC_FOR_FUTURE'), NULL, '')); $fields->attach(form_input_radio(do_lang('CREATE_PERIODIC_FOR'), '', 'periodic_for', $radios, true)); } return do_template('FORM_SCREEN', array('_GUID' => '0b2a4825ec586d9ff557026d9a1e0cca', 'TITLE' => $title, 'TEXT' => $periodic_action == 'make' || $periodic_action == 'replace' ? do_lang_tempcode('PERIODIC_NO_EDIT') : do_lang_tempcode('NEWSLETTER_SEND_TEXT'), 'HIDDEN' => $hidden, 'FIELDS' => $fields->evaluate(), 'SUBMIT_NAME' => $submit_name, 'URL' => $post_url)); }
/** * Get tempcode for a adding/editing form. * * @param SHORT_TEXT The name of the quiz * @param ?integer The number of minutes allowed for completion (NULL: NA) * @param LONG_TEXT The text shown at the start of the quiz * @param LONG_TEXT The text shown at the end of the quiz * @param LONG_TEXT The text shown at the end of the quiz on failure * @param LONG_TEXT Notes * @param integer Percentage correctness required for competition * @param ?TIME The time the quiz is opened (NULL: now) * @param ?TIME The time the quiz is closed (NULL: never) * @param integer The number of winners for this if it is a competition * @param ?integer The minimum number of hours between attempts (NULL: no restriction) * @param ID_TEXT The type * @set SURVEY COMPETITION TEST * @param BINARY Whether this is validated * @param ?string Text for questions (NULL: default) * @param integer The number of points awarded for completing/passing the quiz/test * @param ?AUTO_LINK Newsletter for which a member must be on to enter (NULL: none) * @return tempcode The form fields */ function get_form_fields($name = '', $timeout = NULL, $start_text = '', $end_text = '', $end_text_fail = '', $notes = '', $percentage = 70, $open_time = NULL, $close_time = NULL, $num_winners = 2, $redo_time = NULL, $type = 'COMPETITION', $validated = 1, $text = NULL, $points_for_passing = 0, $tied_newsletter = NULL) { if (is_null($open_time)) { $open_time = time(); } if (is_null($text)) { $text = do_lang('EXAMPLE_QUESTIONS'); } $fields = new ocp_tempcode(); $fields->attach(form_input_line(do_lang_tempcode('NAME'), do_lang_tempcode('DESCRIPTION_NAME'), 'name', $name, true)); $list = new ocp_tempcode(); $list->attach(form_input_list_entry('SURVEY', $type == 'SURVEY', do_lang_tempcode('SURVEY'))); $list->attach(form_input_list_entry('TEST', $type == 'TEST', do_lang_tempcode('TEST'))); $list->attach(form_input_list_entry('COMPETITION', $type == 'COMPETITION', do_lang_tempcode('COMPETITION'))); $fields->attach(form_input_list(do_lang_tempcode('TYPE'), do_lang_tempcode('DESCRIPTION_QUIZ_TYPE'), 'type', $list, NULL, true)); $fields->attach(form_input_huge(do_lang_tempcode('QUESTIONS'), do_lang_tempcode('IMPORT_QUESTIONS_TEXT'), 'text', $text, true)); if ($validated == 0) { global $NON_CANONICAL_PARAMS; $NON_CANONICAL_PARAMS[] = 'validated'; $validated = get_param_integer('validated', 0); if ($validated == 1) { attach_message(do_lang_tempcode('WILL_BE_VALIDATED_WHEN_SAVING')); } } if (addon_installed('unvalidated')) { $fields->attach(form_input_tick(do_lang_tempcode('VALIDATED'), do_lang_tempcode('DESCRIPTION_VALIDATED_SIMPLE'), 'validated', $validated == 1)); } $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('TEST')))); $fields->attach(form_input_integer(do_lang_tempcode('COMPLETION_PERCENTAGE'), do_lang_tempcode('DESCRIPTION_COMPLETION_PERCENTAGE'), 'percentage', $percentage, true)); $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('TEXT'), 'SECTION_HIDDEN' => true))); $fields->attach(form_input_text_comcode(do_lang_tempcode('QUIZ_START_TEXT'), do_lang_tempcode('DESCRIPTION_QUIZ_START_TEXT'), 'start_text', $start_text, false)); $fields->attach(form_input_text_comcode(do_lang_tempcode('QUIZ_END_TEXT'), do_lang_tempcode('DESCRIPTION_QUIZ_END_TEXT'), 'end_text', $end_text, false)); $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('COMPETITION')))); $fields->attach(form_input_integer(do_lang_tempcode('NUM_WINNERS'), do_lang_tempcode('DESCRIPTION_NUM_WINNERS'), 'num_winners', $num_winners, true)); $fields->attach(form_input_text_comcode(do_lang_tempcode('QUIZ_END_TEXT_FAIL'), do_lang_tempcode('DESCRIPTION_QUIZ_END_TEXT_FAIL'), 'end_text_fail', $end_text_fail, false)); $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => is_null($redo_time) && is_null($timeout) && (is_null($open_time) || $open_time <= time()) && is_null($close_time) && $points_for_passing == 0 && is_null($tied_newsletter) && $notes == '', 'TITLE' => do_lang_tempcode('ADVANCED')))); $fields->attach(form_input_integer(do_lang_tempcode('REDO_TIME'), do_lang_tempcode('DESCRIPTION_REDO_TIME'), 'redo_time', $redo_time, false)); $fields->attach(form_input_integer(do_lang_tempcode('TIMEOUT'), do_lang_tempcode('DESCRIPTION_QUIZ_TIMEOUT'), 'timeout', $timeout, false)); $fields->attach(form_input_date(do_lang_tempcode('OPEN_TIME'), do_lang_tempcode('DESCRIPTION_OPEN_TIME'), 'open_time', false, false, true, $open_time, 2)); $fields->attach(form_input_date(do_lang_tempcode('CLOSE_TIME'), do_lang_tempcode('DESCRIPTION_CLOSE_TIME'), 'close_time', true, is_null($close_time), true, is_null($close_time) ? NULL : $close_time, 2)); if (addon_installed('points')) { $fields->attach(form_input_integer(do_lang_tempcode('POINTS_FOR_COMPLETING'), do_lang_tempcode('DESCRIPTION_POINTS_FOR_COMPLETING'), 'points_for_passing', $points_for_passing, true)); } if (addon_installed('newsletter')) { $newsletters = new ocp_tempcode(); $newsletters->attach(form_input_list_entry('', false, do_lang_tempcode('NONE_EM'))); $_newsletters = $GLOBALS['SITE_DB']->query_select('newsletters', array('*'), NULL, 'ORDER BY id'); foreach ($_newsletters as $n) { $newsletters->attach(form_input_list_entry(strval($n['id']), $tied_newsletter == $n['id'], get_translated_text($n['title']))); } if (!$newsletters->is_empty()) { $fields->attach(form_input_list(do_lang_tempcode('TIED_TO_NEWSLETTER'), do_lang_tempcode('DESCRIPTION_TIED_TO_NEWSLETTER'), 'tied_newsletter', $newsletters, NULL, false, false)); } } if (get_value('disable_staff_notes') !== '1') { $fields->attach(form_input_text(do_lang_tempcode('NOTES'), do_lang_tempcode('DESCRIPTION_NOTES'), 'notes', $notes, false)); } return $fields; }
/** * Get the tempcode for viewing/editing the workflow status of the given content * * @param AUTO_LINK The ID of this content in the workflow_content table * @return tempcode The form for this content */ function get_workflow_form($workflow_content_id) { // Load our prerequisites require_lang('workflows'); require_code('form_templates'); require_code('users'); // Do not let guests edit the status of content if (is_guest()) { return new ocp_tempcode(); } ////////////////////////////////////////////////// // Gather the details we need to build the form // ////////////////////////////////////////////////// // These will hold the form code $workflow_form = new ocp_tempcode(); $workflow_fields = new ocp_tempcode(); $workflow_hidden = new ocp_tempcode(); // We already know the content ID $workflow_hidden->attach(form_input_hidden('content_id', strval($workflow_content_id))); // Check if this is a valid piece of content for a workflow $row = $GLOBALS['SITE_DB']->query_select('workflow_content', array('*'), array('id' => $workflow_content_id), '', 1); if (count($row) == 0) { warn_exit(do_lang_tempcode('_MISSING_RESOURCE', get_translated_text($workflow_content_id))); } $row = array_pop($row); // If so then find the workflow name for it $relevant_workflow = $row['workflow_name']; $workflow_hidden->attach(form_input_hidden('workflow_id', strval($relevant_workflow))); // Make sure there are some points to approve $approval_points = get_requirements_for_workflow($relevant_workflow); if ($approval_points == array()) { warn_exit(do_lang_tempcode('_MISSING_RESOURCE', get_translated_text($workflow_content_id))); } ///////////////////////// // Approval tick boxes // ///////////////////////// $available_groups = $GLOBALS['FORUM_DRIVER']->get_members_groups(get_member()); // What groups our user is in $existing_status = array(); // This shows the current approval status, but is not editable $approval_status = array(); // This holds tick-boxes for editing the approval status $send_next = array(); // This holds the details for who to send this to next $approve_count = 0; // This keeps each approval box distinct $send_count = 0; // This keeps the 'send next' boxes distinct $groups_shown = array(); // This keeps track of the groups we've already shown $group_names = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(); // Allows us to find readable group names $permission_limit = false; // Points are added in order, so take notice when we no longer have permission (so we can send to whoever does) $next_point = NULL; // This will store the next workflow point for which we don't have the permission to approve // Get the status of each point $statuses = array(); foreach ($GLOBALS['SITE_DB']->query_select('workflow_content_status', array('workflow_approval_name', 'status_code'), array('workflow_content_id' => $workflow_content_id)) as $stat) { $statuses[$stat['workflow_approval_name']] = $stat['status_code']; } // Assume we can't do anything $have_permission_over_a_point = false; // Now loop through all approval points in workflow order foreach ($approval_points as $point) { // Only show one tick box for each approval point, if any $approval_shown = false; // Go through each group allowed to modify this value... foreach (get_groups_for_point($point) as $allowed_group) { // ... and check whether the user is in it if (!$approval_shown && in_array($allowed_group, $available_groups)) { // If so then remember that we've handled this point $approval_shown = true; // Remember that we can tick something $have_permission_over_a_point = true; // Add the details to the editable tick-box values $approval_status[$approve_count] = array(); $approval_status[$approve_count][] = get_translated_text($point); // Pretty name $approval_status[$approve_count][] = 'approval_' . strval($point); // Name $approval_status[$approve_count][] = array_key_exists($point, $statuses) ? $statuses[$point] : 0; // The value (defaults to 0) $approval_status[$approve_count][] = do_lang_tempcode('APPROVAL_TICK_DESCRIPTION', get_translated_text($point)); // Description $approval_status[$approve_count][] = false; // Not disabled, since we have permission // Add the details to the uneditable, existing status values $existing_status[$approve_count] = array(); $existing_status[$approve_count][] = get_translated_text($point); // Pretty name $existing_status[$approve_count][] = 'existing_' . strval($point); // Name if (array_key_exists($point, $statuses) && $statuses[$point] == 1) { $existing_status[$approve_count][] = 1; // The value (1 due to our if condition) $existing_status[$approve_count][] = do_lang_tempcode('ALREADY_APPROVED', get_translated_text($point)); // Description } else { $existing_status[$approve_count][] = 0; // The value defaults to 0 $existing_status[$approve_count][] = do_lang_tempcode('NOT_YET_APPROVED', get_translated_text($point)); // Description } $existing_status[$approve_count][] = true; // Disabled, since this is for informative purposes only // Increment the unique ID for the array elements $approve_count = $approve_count + 1; } // We want the send boxes to name usergroups, rather than // approval points, so we may as well add those here. // Take care not to add groups we've already got! if (!in_array($allowed_group, $groups_shown)) { $send_next[$allowed_group] = array(); $send_next[$allowed_group][] = $group_names[$allowed_group]; // Pretty name $send_next[$allowed_group][] = 'send_' . strval($allowed_group); // Name // Set the default value. We want groups allowed to approve the // next+1 point ticked (assuming we're approving the next one) // For simplicity, let's keep these unticked for now. //if (in_array($allowed_group['usergroup'],$groups_shown)) //{ $send_next[$allowed_group][] = false; //} $send_next[$allowed_group][] = do_lang_tempcode('NEXT_APPROVAL_DESCRIPTION', $group_names[$allowed_group]); // Description $groups_shown[] = $allowed_group; } } // If it's not handled at this point, we don't have permission if (!$approval_shown) { // Thus we should show a disabled check box $existing_status[$approve_count] = array(); $existing_status[$approve_count][] = get_translated_text($point); // Pretty name $existing_status[$approve_count][] = 'approval_' . strval($point); // Name $existing_status[$approve_count][] = array_key_exists($point, $statuses) ? $statuses[$point] : 0; // Value (defaults to 0) $existing_status[$approve_count][] = do_lang_tempcode('APPROVAL_TICK_DESCRIPTION', get_translated_text($point)); // Description $existing_status[$approve_count][] = true; // Disabled, we have no permission // Increment the unique ID for the array elements $approve_count = $approve_count + 1; // If this is the first entry we're not permitted to change and // it is not already ticked... if (!$permission_limit && (!array_key_exists($point, $statuses) || $statuses[$point] == 0)) { // ... remember it (since we can send-to those who are // permitted) $next_point = $point; $permission_limit = true; } } } // If we have no control over this workflow then don't bother showing it if (!$have_permission_over_a_point) { return new ocp_tempcode(); } /////////////////// // Send-to boxes // /////////////////// // Now we attempt to impose some sort of order to the send-to boxes. // The order we're going to use is to collect groups where the sum of // the workflow positions they can approve is equal, and put the // collections in ascending order. The collections are ordered based // on the group's average workflow approval position. Any further // ambiguity is not worth considering. $group_scores = array(); // Track the sum of positions for each group $group_counts = array(); // Track the number of points each group can approve (so we can calculate the average) $active_groups = array(); // Note which groups have permission to approve the next workflow point we can't do ourselves // Get all of the approval points and all of the groups foreach ($approval_points as $point) { foreach (get_groups_for_point($point) as $group) { // See whether this group should be active if ($next_point == $point) { $active_groups[] = $group; } // Add on the point's position to this group's score if (array_key_exists($group, $group_scores)) { $group_scores[$group] = $group_scores[$group] + get_requirement_position($point, $relevant_workflow); } else { $group_scores[$group] = get_requirement_position($point, $relevant_workflow); } // Now increment the group's approval point count if (array_key_exists($group, $group_counts)) { $group_counts[$group] = $group_counts[$group] + 1; } else { $group_counts[$group] = 1; } } } // Now we can order the groups: $group_order = array(); // This will store collections of groups in order of score foreach ($group_scores as $group_id => $score) { // Make a new collection if we've not got one if (!array_key_exists($score, $group_order)) { $group_order[$score] = array(); } // Add this group to the collection $group_order[$score][] = $group_id; } // Finally we can get the tick-box details we found earlier and put // them in the right order $send_to_boxes = array(); foreach ($group_order as $score => $collection) { // Add the group if its the only one if (count($collection) == 1) { // Before adding the tick box, see if it should be active if (in_array($collection[0], $active_groups)) { $send_next[$collection[0]][2] = 1; } $send_to_boxes[] = $send_next[$collection[0]]; } else { // Otherwise order the collection first $collection_order = array(); foreach ($collection as $group_id) { // Work out the average position of each group's approval // points (we need an int for use as an index, but add a // couple of orders of magnitude to give us 2 more sig figs) $group_average = intval(floatval($score) / floatval($group_counts[$group_id]) * 100); // Make a new collection if we've not got one if (!array_key_exists($group_average, $collection_order)) { $collection_order[$group_average] = array(); } // Add this group to the average collection $collection_order[$group_average][] = $group_id; } // Now we can add them in order of average foreach ($collection_order as $average_collection) { foreach ($average_collection as $group_id) { // Before adding the tick box, see if it should be active if (in_array($group_id, $active_groups)) { $send_next[$group_id][2] = 1; } $send_to_boxes[] = $send_next[$group_id]; } } } } // Now tack the original submitter onto the end of the send-to list, // if we know who it is $submitter = get_submitter_of_workflow_content($workflow_content_id); if (!is_null($submitter)) { $submitter_details = array(); // Build the array independently $submitter_details[] = $GLOBALS['FORUM_DRIVER']->get_username($submitter) . ' (' . do_lang('SUBMITTER') . ')'; $submitter_details[] = 'send_author'; // Name $submitter_details[] = false; // Value $submitter_details[] = do_lang_tempcode('NEXT_APPROVAL_AUTHOR', $GLOBALS['FORUM_DRIVER']->get_username($submitter)); // Description $send_to_boxes[] = $submitter_details; // Then tack it on the end } /* NOTE: Not currently used; content becomes live once all points are * approved /////////////////// // Live tick-box // /////////////////// // The 'Live' tickbox is just the regular 'validated' box with a thin // veneer of approval logic. It should only be enabled if we have // permission over all approval points (ie. there is no 'next' point) if (is_null($next_point)) { $live_box = form_input_tick(do_lang_tempcode('WORKFLOW_LIVE'),do_lang_tempcode('WORKFLOW_LIVE_DESCRIPTION'),'validated',$validated,NULL,'1',false); } else { $live_box = form_input_tick(do_lang_tempcode('WORKFLOW_LIVE'),do_lang_tempcode('WORKFLOW_LIVE_DESCRIPTION'),'validated',$validated,NULL,'1',true); } */ //////////////////////// // Now build the form // //////////////////////// // Bail out if there's nothing to the workflow if ($approval_status == array()) { return new ocp_tempcode(); } // Attach the title to the form first, along with usage info $workflow_fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => NULL, 'HELP' => do_lang_tempcode('WORKFLOW_USAGE')))); // Show the current status next $workflow_fields->attach(form_input_various_ticks($existing_status, '', NULL, do_lang_tempcode('CURRENT_APPROVAL_STATUS'), false)); // Attach the workflow tick boxes next $workflow_fields->attach(form_input_various_ticks($approval_status, '', NULL, do_lang_tempcode('POINTS_TO_APPROVE'), false)); // Add the 'live' tickbox // NOTE: Not used at the moment; content becomes live once all points // have been approved //$workflow_fields->attach($live_box); // Add a section for notes $notes = $GLOBALS['SITE_DB']->query_select('workflow_content', array('notes'), array('id' => $workflow_content_id)); $workflow_fields->attach(form_input_huge(do_lang('NOTES'), do_lang('WORKFLOW_NOTES_DESCRIPTION'), 'workflow_notes', $notes[0]['notes'], false, NULL, 6, '', true)); // Set who to send it to next $workflow_fields->attach(form_input_various_ticks($send_to_boxes, do_lang_tempcode('NEXT_APPROVAL_SIDE_DESCRIPTION'), NULL, do_lang_tempcode('NEXT_APPROVAL'), false)); // Set the URL for handling the response to this form $post_url = build_url(array('page' => '_SELF', 'type' => 'workflow'), '_SELF'); // Set the URL to return to after the handling has taken place $workflow_hidden->attach(form_input_hidden('return_url', get_self_url(true))); // Add all of these to the form $workflow_form->attach(do_template('FORM', array('FIELDS' => $workflow_fields, 'HIDDEN' => $workflow_hidden, 'TEXT' => '', 'URL' => $post_url, 'SUBMIT_NAME' => do_lang_tempcode('SUBMIT_WORKFLOW_CHANGES'), 'SKIP_REQUIRED' => true))); // Then pass it to whoever wanted it return put_in_standard_box($workflow_form, do_lang_tempcode('WORKFLOW_STATUS')); }
/** * AJAX script for HTML<>Comcode conversion (and Comcode-Text>Comcode-XML). */ function comcode_convert_script() { header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past global $EXTRA_HEAD; if (!isset($EXTRA_HEAD)) { $EXTRA_HEAD = new ocp_tempcode(); } $EXTRA_HEAD->attach('<meta name="robots" content="noindex" />'); // XHTMLXHTML require_lang('comcode'); convert_data_encodings(true); $data = post_param('data', NULL, false, false); if (is_null($data)) { $title = get_page_title('_COMCODE'); $fields = new ocp_tempcode(); require_code('form_templates'); $fields->attach(form_input_huge(do_lang_tempcode('TEXT'), '', 'data', '', true)); $fields->attach(form_input_tick('Convert HTML to Comcode', '', 'from_html', false)); $fields->attach(form_input_tick('Convert to semihtml', '', 'semihtml', false)); $fields->attach(form_input_tick('Lax mode (less parse rules)', '', 'lax', false)); $hidden = new ocp_tempcode(); $hidden->attach(form_input_hidden('to_comcode_xml', strval(either_param_integer('to_comcode_xml', 0)))); $out2 = globalise(do_template('FORM_SCREEN', array('_GUID' => 'dd82970fa1196132e07049871c51aab7', 'TITLE' => $title, 'SUBMIT_NAME' => do_lang_tempcode('VIEW'), 'TEXT' => '', 'HIDDEN' => $hidden, 'URL' => find_script('comcode_convert', true), 'FIELDS' => $fields)), NULL, '', true); $out2->evaluate_echo(); return; } $panel = either_param_integer('panel', NULL); if (!is_null($panel)) { global $TEMPCODE_SETGET; if ($panel == 0) { $TEMPCODE_SETGET['in_panel'] = '0'; } else { $TEMPCODE_SETGET['in_panel'] = '1'; } } if (either_param_integer('to_comcode_xml', 0) == 1) { require_code('comcode_conversion'); $out = comcode_text__to__comcode_xml($data); } elseif (either_param_integer('from_html', 0) == 1) { require_code('comcode_from_html'); $out = trim(semihtml_to_comcode($data)); } else { if (either_param_integer('lax', 0) == 1) { $GLOBALS['LAX_COMCODE'] = true; } if (either_param_integer('is_semihtml', 0) == 1) { require_code('comcode_from_html'); $data = semihtml_to_comcode($data); } $db = $GLOBALS['SITE_DB']; if (get_param_integer('forum_db', 0) == 1) { $db = $GLOBALS['FORUM_DB']; } $tpl = comcode_to_tempcode($data, get_member(), false, 60, NULL, $db, either_param_integer('semihtml', 0) == 1, false, false, false); $evaluated = $tpl->evaluate(); $out = ''; if ($evaluated != '') { if (get_param_integer('css', 0) == 1) { global $CSSS; unset($CSSS['global']); unset($CSSS['no_cache']); $out .= static_evaluate_tempcode(css_tempcode()); } if (get_param_integer('javascript', 0) == 1) { global $JAVASCRIPTS; unset($JAVASCRIPTS['javascript']); unset($JAVASCRIPTS['javascript_staff']); $out .= static_evaluate_tempcode(javascript_tempcode()); } } $out .= trim(trim($evaluated)); } if (either_param_integer('fix_bad_html', 0) == 1) { require_code('xhtml'); $new = xhtmlise_html($out, true); if (preg_replace('#<!--.*-->#Us', '', preg_replace('#\\s+#', '', $new)) != preg_replace('#<!--.*-->#Us', '', preg_replace('#\\s+#', '', $out))) { /*$myfile=fopen(get_file_base().'/a','wb'); fwrite($myfile,preg_replace('#<!--.*-->#Us','',preg_replace('#\s+#',chr(10),$new))); fclose($myfile); $myfile=fopen(get_file_base().'/b','wb'); fwrite($myfile,preg_replace('#<!--.*-->#Us','',preg_replace('#\s+#',chr(10),$out))); fclose($myfile);*/ $out = $new . do_lang('BROKEN_XHTML_FIXED'); } } if (either_param_integer('keep_skip_rubbish', 0) == 0) { @ini_set('ocproducts.xss_detect', '0'); $box_title = get_param('box_title', ''); if (is_object($out)) { $out = $out->evaluate(); } if ($box_title != '' && $out != '') { $out = static_evaluate_tempcode(put_in_standard_box(make_string_tempcode($out), $box_title)); } header('Content-Type: text/xml'); echo '<?xml version="1.0" encoding="' . get_charset() . '"?' . '>'; echo '<request><result>'; echo xmlentities($out); echo '</result></request>'; } else { header('Content-type: text/plain; charset=' . get_charset()); echo $out; } }