Esempio n. 1
0
 /**
  * The UI to run a multi-moderation.
  *
  * @return tempcode		The UI
  */
 function multimod()
 {
     $mm_id = intval(substr(get_param('type', 'misc'), 3));
     $topic_id = get_param_integer('id');
     $this->check_has_mod_access($topic_id);
     $topic_info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('*'), array('id' => $topic_id), '', 1);
     if (!array_key_exists(0, $topic_info)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $topic_title = $topic_info[0]['t_cache_first_title'];
     $this->handle_topic_breadcrumbs($topic_info[0]['t_forum_id'], $topic_id, $topic_info[0]['t_cache_first_title'], do_lang_tempcode('_PERFORM_MULTI_MODERATION', escape_html($topic_title)));
     $title = get_page_title('_PERFORM_MULTI_MODERATION', true, array(escape_html($topic_title)));
     $mm = $GLOBALS['FORUM_DB']->query_select('f_multi_moderations', array('*'), array('id' => $mm_id), '', 1);
     if (!array_key_exists(0, $mm)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $_mm = $mm[0];
     $post_text = $_mm['mm_post_text'];
     $submit_name = do_lang_tempcode('PERFORM_MULTI_MODERATION');
     $post_url = build_url(array('page' => '_SELF', 'type' => '_multimod', 'id' => $topic_id, 'mm_id' => $mm_id), '_SELF', NULL, true);
     $fields = new ocp_tempcode();
     $hidden = new ocp_tempcode();
     $hidden->attach(build_keep_post_fields());
     $hidden->attach(build_keep_form_fields());
     $fields->attach(form_input_text(do_lang_tempcode('MM_POST_TEXT'), do_lang_tempcode('DESCRIPTION_MM_POST_TEXT'), 'post_text', $post_text, false));
     $options = array();
     if (get_value('disable_skip_sig') !== '1') {
         if (addon_installed('ocf_signatures')) {
             $options[] = array(do_lang_tempcode('SKIP_SIGNATURE'), 'skip_sig', false, do_lang_tempcode('DESCRIPTION_SKIP_SIGNATURE'));
         }
     }
     if (get_value('disable_post_emphasis') !== '1') {
         $options[] = array(do_lang_tempcode('EMPHASISED'), 'is_emphasised', true, do_lang_tempcode('DESCRIPTION_EMPHASISED'));
     }
     $fields->attach(form_input_various_ticks($options, ''));
     $fields->attach(form_input_line(do_lang_tempcode('REASON'), do_lang_tempcode('OPTIONAL_REASON'), 'reason', '', false));
     $mm_title = get_translated_text($_mm['mm_name'], $GLOBALS['FORUM_DB']);
     $action_list = new ocp_tempcode();
     if ($_mm['mm_open_state'] == 1) {
         $action_list->attach(do_lang_tempcode('MULTI_MODERATION_WILL_OPEN'));
     }
     if ($_mm['mm_open_state'] == 0) {
         $action_list->attach(do_lang_tempcode('MULTI_MODERATION_WILL_CLOSE'));
     }
     if ($_mm['mm_pin_state'] == 1) {
         $action_list->attach(do_lang_tempcode('MULTI_MODERATION_WILL_PIN'));
     }
     if ($_mm['mm_pin_state'] == 0) {
         $action_list->attach(do_lang_tempcode('MULTI_MODERATION_WILL_UNPIN'));
     }
     if ($_mm['mm_sink_state'] == 1) {
         $action_list->attach(do_lang_tempcode('MULTI_MODERATION_WILL_SINK'));
     }
     if ($_mm['mm_sink_state'] == 0) {
         $action_list->attach(do_lang_tempcode('MULTI_MODERATION_WILL_UNSINK'));
     }
     if ($_mm['mm_title_suffix'] != '') {
         $action_list->attach(do_lang_tempcode('MULTI_MODERATION_WILL_TITLE_SUFFIX', escape_html($_mm['mm_title_suffix'])));
     }
     if (!is_null($_mm['mm_move_to'])) {
         $action_list->attach(do_lang_tempcode('MULTI_MODERATION_WILL_MOVE', ocf_forum_breadcrumbs($_mm['mm_move_to'])));
     }
     $action_list->attach(do_lang_tempcode('MULTI_MODERATION_WILL_POST'));
     $text = do_lang_tempcode('MULTI_MODERATION_WILL', make_string_tempcode($mm_title), $action_list);
     return do_template('FORM_SCREEN', array('_GUID' => '2eef0c445d207bb10ff3fd28ea32ef8c', 'STAFF_HELP_URL' => brand_base_url() . '/docs' . strval(ocp_version()) . '/pg/tut_forum_helpdesk', 'PREVIEW' => true, 'HIDDEN' => $hidden, 'TITLE' => $title, 'TEXT' => $text, 'URL' => $post_url, 'FIELDS' => $fields, 'SUBMIT_NAME' => $submit_name));
 }
Esempio n. 2
0
 /**
  * The UI to edit a menu.
  *
  * @return tempcode		The UI
  */
 function edit_menu()
 {
     if (!has_js()) {
         warn_exit(do_lang_tempcode('MSG_JS_NEEDED'));
     }
     $id = get_param('id', '');
     if ($id == '') {
         $id = get_param('id_new');
     }
     if (substr($id, 0, 1) == '_') {
         warn_exit(do_lang_tempcode('MENU_UNDERSCORE_RESERVED'));
     }
     require_code('type_validation');
     if (!is_alphanumeric($id, true)) {
         warn_exit(do_lang_tempcode('BAD_CODENAME'));
     }
     if ($id == 'zone_menu' && get_option('use_custom_zone_menu') == '0') {
         $config_url = build_url(array('page' => 'admin_config', 'type' => 'category', 'id' => 'THEME'), get_module_zone('admin_config'));
         attach_message(do_lang_tempcode('EDITING_UNUSED_MENU', escape_html($config_url->evaluate())), 'notice');
     }
     $title = get_page_title('_EDIT_MENU', true, array(escape_html($id)));
     $clickable_sections = get_param_integer('clickable_sections', 0) == 1;
     // This is set to '1 if we have a menu type where pop out sections may be clicked on to be loaded. If we do then we make no UI distinction between page nodes and contracted/expanded, so people don't get compelled to choose a URL for everything, it simply becomes an option for them.
     // This will be a templates for branches created dynamically
     $t_id = 'replace_me_with_random';
     $branch = do_template('MENU_EDITOR_BRANCH', array('_GUID' => '59d5c9bebecdac1440112ef8301d7c67', 'CLICKABLE_SECTIONS' => $clickable_sections ? 'true' : 'false', 'I' => $t_id, 'CHILD_BRANCH_TEMPLATE' => '', 'CHILD_BRANCHES' => ''));
     $child_branch_template = do_template('MENU_EDITOR_BRANCH_WRAP', array('_GUID' => 'fb16265f553127b47dfdaf33a420136b', 'DISPLAY' => $clickable_sections ? 'display: block' : 'display: none', 'CLICKABLE_SECTIONS' => $clickable_sections, 'ORDER' => 'replace_me_with_order', 'PARENT' => 'replace_me_with_parent', 'BRANCH_TYPE' => '0', 'NEW_WINDOW' => '0', 'CHECK_PERMS' => '0', 'CAPTION_LONG' => '', 'CAPTION' => '', 'URL' => '', 'PAGE_ONLY' => '', 'THEME_IMG_CODE' => '', 'I' => $t_id, 'BRANCH' => $branch));
     $order = 0;
     $menu_items = $GLOBALS['SITE_DB']->query_select('menu_items', array('*'), array('i_menu' => $id), 'ORDER BY i_parent,i_order');
     $child_branches = $this->menu_branch($id, NULL, $order, $clickable_sections, $menu_items);
     $root_branch = do_template('MENU_EDITOR_BRANCH', array('CLICKABLE_SECTIONS' => $clickable_sections ? 'true' : 'false', 'CHILD_BRANCH_TEMPLATE' => $child_branch_template, 'CHILD_BRANCHES' => $child_branches, 'I' => ''));
     $map = array('page' => '_SELF', 'type' => '_edit', 'id' => $id);
     if (get_param('redirect', '!') != '!') {
         $map['redirect'] = get_param('redirect');
     }
     $post_url = build_url($map, '_SELF');
     $map = array('page' => '_SELF', 'type' => '_edit', 'id' => $id);
     // Actually same as edit URL, just we put this into an empty post form
     if (get_param('redirect', '!') != '!') {
         $map['redirect'] = get_param('redirect');
     }
     $delete_url = build_url($map, '_SELF');
     require_code('form_templates');
     $fields_template = new ocp_tempcode();
     //$fields_template->attach(form_input_line(do_lang_tempcode('CAPTION'),do_lang_tempcode('MENU_ENTRY_CAPTION'),'caption','',true)); This is editable in the tree structure instead
     $fields_template->attach(form_input_line(do_lang_tempcode('LINK'), do_lang_tempcode('MENU_ENTRY_URL'), 'url', '', false));
     $options = array(array(do_lang_tempcode('MENU_ENTRY_NEW_WINDOW'), 'new_window', false, new ocp_tempcode()), array(do_lang_tempcode('MENU_ENTRY_CHECK_PERMS'), 'check_perms', true, do_lang_tempcode('DESCRIPTION_MENU_ENTRY_CHECK_PERMS')));
     $fields_template->attach(form_input_various_ticks($options, '', NULL, do_lang_tempcode('OPTIONS'), false));
     $list = new ocp_tempcode();
     if (!$clickable_sections) {
         $list->attach(form_input_list_entry('page', false, do_lang_tempcode('PAGE')));
     }
     $list->attach(form_input_list_entry('branch_minus', false, do_lang_tempcode('CONTRACTED_BRANCH')));
     $list->attach(form_input_list_entry('branch_plus', false, do_lang_tempcode('EXPANDED_BRANCH')));
     $fields_template->attach(form_input_list(do_lang_tempcode('BRANCH_TYPE'), do_lang_tempcode('MENU_ENTRY_BRANCH'), 'branch_type', $list));
     $fields_template->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => true, 'TITLE' => do_lang_tempcode('ADVANCED'))));
     $fields_template->attach(form_input_line(do_lang_tempcode('CAPTION_LONG'), do_lang_tempcode('MENU_ENTRY_CAPTION_LONG'), 'caption_long', '', false));
     $list = new ocp_tempcode();
     $list->attach(form_input_list_entry('', false, do_lang_tempcode('NONE_EM')));
     require_code('themes2');
     $list->attach(nice_get_theme_images(NULL, NULL, false, true, 'menu_items/'));
     $fields_template->attach(form_input_list(do_lang_tempcode('THEME_IMAGE'), do_lang_tempcode('DESCRIPTION_THEME_IMAGE_FOR_MENU_ITEM'), 'theme_img_code', $list, NULL, false, false));
     $fields_template->attach(form_input_line(do_lang_tempcode('RESTRICT_PAGE_VISIBILITY'), do_lang_tempcode('MENU_ENTRY_MATCH_KEYS'), 'match_tags', '', false));
     require_javascript('javascript_ajax');
     require_javascript('javascript_more');
     require_javascript('javascript_tree_list');
     list($warning_details, $ping_url) = handle_conflict_resolution();
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('MENU_MANAGEMENT'))));
     $all_menus = array();
     $menu_rows = $GLOBALS['SITE_DB']->query_select('menu_items', array('DISTINCT i_menu'), NULL, 'ORDER BY i_menu');
     foreach ($menu_rows as $menu_row) {
         if ($menu_row['i_menu'] != $id) {
             $all_menus[] = $menu_row['i_menu'];
         }
     }
     return do_template('MENU_EDITOR_SCREEN', array('_GUID' => 'd2bc26eaea38f3d5b3221be903ff541e', 'ALL_MENUS' => $all_menus, 'MENU_NAME' => $id, 'DELETE_URL' => $delete_url, 'PING_URL' => $ping_url, 'WARNING_DETAILS' => $warning_details, 'FIELDS_TEMPLATE' => $fields_template, 'HIGHEST_ORDER' => strval($order), 'URL' => $post_url, 'CHILD_BRANCH_TEMPLATE' => $child_branch_template, 'ROOT_BRANCH' => $root_branch, 'TITLE' => $title));
 }
Esempio n. 3
0
 /**
  * Renders a screen for setting permissions on approval points.
  *
  * @return tempcode		The UI
  */
 function second_screen()
 {
     require_code('form_templates');
     // See if we're redefining everything
     $redefining = array_key_exists('redefine_points', $_POST);
     // Grab all of the requested points
     $points = array_map('trim', explode("\n", trim(post_param('points'))));
     // Throw out whitespace
     $temp_points = array();
     foreach ($points as $p) {
         if (strlen(trim($p)) > 0) {
             $temp_points[] = trim($p);
         }
     }
     $points = $temp_points;
     unset($temp_points);
     // Clean them up a bit. We'll allow spaces, but no other punctuation.
     $clean_points = array();
     foreach ($points as $p) {
         $clean_points[] = implode(' ', array_map('strip_tags', explode(' ', $p)));
     }
     $points = $clean_points;
     unset($clean_points);
     // Find any points which are already defined
     $all_points = get_all_approval_points();
     // This will hold new points
     $clarify_points = array();
     // This will hold existing points we're redefining
     $redefine_points = array();
     // See if we need to define any
     foreach ($points as $p) {
         if (!in_array($p, $all_points)) {
             // Found an undefined point. We need more information.
             $clarify_points[] = $p;
         } elseif ($redefining) {
             $redefine_points[] = $p;
         }
     }
     // These will hold our form fields
     $fields = new ocp_tempcode();
     $hidden = new ocp_tempcode();
     // Pass through the previous screen's data
     foreach (array('points', 'is_default', 'name') as $n) {
         $hidden->attach(form_input_hidden($n, post_param($n, '')));
     }
     // We need a list of groups so that the user can choose those to give
     // permission to
     $usergroups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(true, true, false, NULL, NULL);
     // Add the form elements for each section
     if (count($clarify_points) > 0) {
         $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang('DEFINE_WORKFLOW_POINTS'), 'HELP' => do_lang_tempcode('DEFINE_WORKFLOW_POINTS_HELP', implode(', ', $clarify_points)))));
         $counter = 0;
         foreach ($clarify_points as $p) {
             // Add a code to reference these elements by later
             $hidden->attach(form_input_hidden('code_' . strval($counter), $p));
             // Now add a list of the groups to allow
             $content = array();
             foreach ($usergroups as $group_id => $group_name) {
                 $content[] = array($group_name, 'groups_' . strval($counter) . '[' . strval($group_id) . ']', false, '');
             }
             $fields->attach(form_input_various_ticks($content, do_lang('WORKFLOW_POINT_GROUPS_DESC', $p), NULL, do_lang('WORKFLOW_POINT_GROUPS', $p), true));
             $counter++;
         }
     }
     if (count($redefine_points) > 0) {
         $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang('REDEFINE_WORKFLOW_POINTS'), 'HELP' => do_lang('REDEFINE_WORKFLOW_POINTS_HELP'))));
         // These points already exist, so look them up
         $all_points = array_flip(get_all_approval_points());
         foreach ($redefine_points as $p) {
             // Add a code to reference these elements by later
             $hidden->attach(form_input_hidden('redef_' . strval($all_points[$p]), $p));
             // Now add a list of the groups to allow, defaulting to those which
             // already have permission
             $groups = get_groups_for_point($all_points[$p], false);
             $content = array();
             foreach ($usergroups as $group_id => $group_name) {
                 $content[] = array($group_name, 'redef_groups_' . strval($all_points[$p]) . '[' . strval($group_id) . ']', in_array($group_id, $groups), '');
             }
             $fields->attach(form_input_various_ticks($content, do_lang('WORKFLOW_POINT_GROUPS_DESC', $p), NULL, do_lang('WORKFLOW_POINT_GROUPS', $p), true));
         }
     }
     $self_url = get_self_url();
     return do_template('FORM_SCREEN', array('TITLE' => do_template('SCREEN_TITLE', array('TITLE' => do_lang('DEFINE_WORKFLOW_POINTS'), 'HELP_URL' => '')), 'FIELDS' => $fields, 'TEXT' => '', 'HIDDEN' => $hidden, 'URL' => is_object($self_url) ? $self_url->evaluate() : $self_url, 'SUBMIT_NAME' => do_lang_tempcode('PROCEED')));
 }
Esempio n. 4
0
 /**
  * Get tempcode for a gallery adding/editing form.
  *
  * @param  ID_TEXT			The gallery codename
  * @param  SHORT_TEXT		The full human-readeable name of the gallery
  * @param  LONG_TEXT			The description of the gallery
  * @param  SHORT_TEXT		Teaser text for the gallery
  * @param  LONG_TEXT			Hidden notes associated with the gallery
  * @param  ID_TEXT			The parent gallery (blank: no parent)
  * @param  BINARY				Whether images may be put in this gallery
  * @param  BINARY				Whether videos may be put in this gallery
  * @param  BINARY				Whether the gallery serves as a container for automatically created member galleries
  * @param  ?BINARY			Whether the gallery uses the flow mode interface (NULL: pick statistically based on current usage of other galleries)
  * @param  ?URLPATH			The representative image of the gallery (NULL: none)
  * @param  ?URLPATH			Watermark (NULL: none)
  * @param  ?URLPATH			Watermark (NULL: none)
  * @param  ?URLPATH			Watermark (NULL: none)
  * @param  ?URLPATH			Watermark (NULL: none)
  * @param  ?BINARY			Whether rating is allowed (NULL: decide statistically, based on existing choices)
  * @param  ?SHORT_INTEGER	Whether comments are allowed (0=no, 1=yes, 2=review style) (NULL: decide statistically, based on existing choices)
  * @return array				A pair: the tempcode for the visible fields, and the tempcode for the hidden fields
  */
 function get_form_fields($name = '', $fullname = '', $description = '', $teaser = '', $notes = '', $parent_id = '', $accept_images = 1, $accept_videos = 1, $is_member_synched = 0, $flow_mode_interface = NULL, $rep_image = NULL, $watermark_top_left = NULL, $watermark_top_right = NULL, $watermark_bottom_left = NULL, $watermark_bottom_right = NULL, $allow_rating = NULL, $allow_comments = NULL)
 {
     list($allow_rating, $allow_comments, ) = $this->choose_feedback_fields_statistically($allow_rating, $allow_comments, 1);
     global $NON_CANONICAL_PARAMS;
     $NON_CANONICAL_PARAMS[] = 'cat';
     $NON_CANONICAL_PARAMS[] = 'validated';
     if (is_null($flow_mode_interface)) {
         $cnt = $GLOBALS['SITE_DB']->query_value('galleries', 'COUNT(*)');
         if ($cnt < 5000) {
             $flow_mode_interface = intval(round($GLOBALS['SITE_DB']->query_value('galleries', 'AVG(flow_mode_interface)')));
             // Determine default based on what is 'the norm' currently. Sometimes maths is beautiful :)
         } else {
             $flow_mode_interface = intval(round($GLOBALS['SITE_DB']->query_value('galleries', 'AVG(flow_mode_interface)', array('parent_id' => 'root'))));
             // Determine default based on what is 'the norm' currently. Sometimes maths is beautiful :)
         }
     }
     $fields = new ocp_tempcode();
     require_code('form_templates');
     $fields->attach(form_input_line(do_lang_tempcode('TITLE'), do_lang_tempcode('DESCRIPTION_TITLE'), 'fullname', $fullname, true));
     if ($name != 'root') {
         $fields->attach(form_input_codename(do_lang_tempcode('CODENAME'), do_lang_tempcode('DESCRIPTION_CODENAME'), 'name', $name, true));
     }
     $fields->attach(form_input_text_comcode(do_lang_tempcode('DESCRIPTION'), do_lang_tempcode('DESCRIPTION_DESCRIPTION'), 'description', $description, false));
     if ($parent_id == '') {
         $parent_id = get_param('cat', '');
     }
     if ($name != 'root') {
         $fields->attach(form_input_tree_list(do_lang_tempcode('PARENT'), do_lang_tempcode('DESCRIPTION_PARENT'), 'parent_id', NULL, 'choose_gallery', array('filter' => 'only_conventional_galleries', 'purity' => true, 'addable_filter' => true), true, $parent_id));
     }
     $fields->attach(form_input_various_ticks(array(array(do_lang_tempcode('ACCEPT_IMAGES'), 'accept_images', $accept_images == 1, do_lang_tempcode('DESCRIPTION_ACCEPT_IMAGES')), array(do_lang_tempcode('ACCEPT_VIDEOS'), 'accept_videos', $accept_videos == 1, do_lang_tempcode('DESCRIPTION_ACCEPT_VIDEOS'))), new ocp_tempcode(), NULL, do_lang_tempcode('ACCEPTED_MEDIA_TYPES')));
     $fields->attach(form_input_tick(do_lang_tempcode('FLOW_MODE_INTERFACE'), do_lang_tempcode('DESCRIPTION_FLOW_MODE_INTERFACE'), 'flow_mode_interface', $flow_mode_interface == 1));
     $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => $rep_image == '' && $teaser == '' && $is_member_synched == 0, 'TITLE' => do_lang_tempcode('ADVANCED'))));
     $fields->attach(form_input_upload(do_lang_tempcode('REPRESENTATIVE_IMAGE'), do_lang_tempcode('DESCRIPTION_REPRESENTATIVE_IMAGE_GALLERY'), 'rep_image', false, $rep_image, NULL, true, str_replace(' ', '', get_option('valid_images'))));
     // Only show tease option if tease block being used
     $teaser_shows = false;
     $zones = find_all_zones(false, true);
     $pages = array();
     foreach ($zones as $_zone) {
         $pages[$_zone[0]] = find_all_pages_wrap($_zone[0], true);
     }
     foreach ($pages as $zone => $under) {
         foreach ($under as $filename => $type) {
             if (substr(strtolower($filename), -4) == '.txt') {
                 $matches = array();
                 $contents = file_get_contents(zone_black_magic_filterer((substr($type, 0, 15) == 'comcode_custom/' ? get_custom_file_base() : get_file_base()) . '/' . ($zone == '' ? '' : $zone . '/') . 'pages/' . $type . '/' . $filename));
                 $fallback = get_file_base() . '/' . ($zone == '' ? '' : $zone . '/') . 'pages/comcode/' . fallback_lang() . '/' . $filename;
                 if (file_exists($fallback)) {
                     $contents .= file_get_contents($fallback);
                 }
                 if (preg_match('#\\[block[^\\]]*\\]main_gallery_tease\\[/block\\]#', $contents, $matches) != 0) {
                     $teaser_shows = true;
                 }
             }
         }
     }
     if ($teaser_shows) {
         $fields->attach(form_input_line_comcode(do_lang_tempcode('TEASER'), do_lang_tempcode('DESCRIPTION_TEASER'), 'teaser', $teaser, false));
     }
     $fields->attach(form_input_tick(do_lang_tempcode('IS_MEMBER_SYNCHED'), do_lang_tempcode('DESCRIPTION_IS_MEMBER_SYNCHED_GALLERY'), 'is_member_synched', $is_member_synched == 1));
     $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => is_null($watermark_top_left) && is_null($watermark_top_right) && is_null($watermark_bottom_left) && is_null($watermark_bottom_right), 'TITLE' => do_lang_tempcode('WATERMARKING'))));
     $fields->attach(form_input_upload(do_lang_tempcode('_WATERMARK', do_lang_tempcode('TOP_LEFT')), do_lang_tempcode('_DESCRIPTION_WATERMARK', do_lang_tempcode('TOP_LEFT')), 'watermark_top_left', false, $watermark_top_left, NULL, true, str_replace(' ', '', get_option('valid_images'))));
     $fields->attach(form_input_upload(do_lang_tempcode('_WATERMARK', do_lang_tempcode('TOP_RIGHT')), do_lang_tempcode('_DESCRIPTION_WATERMARK', do_lang_tempcode('TOP_RIGHT')), 'watermark_top_right', false, $watermark_top_right, NULL, true, str_replace(' ', '', get_option('valid_images'))));
     $fields->attach(form_input_upload(do_lang_tempcode('_WATERMARK', do_lang_tempcode('BOTTOM_LEFT')), do_lang_tempcode('_DESCRIPTION_WATERMARK', do_lang_tempcode('BOTTOM_LEFT')), 'watermark_bottom_left', false, $watermark_bottom_left, NULL, true, str_replace(' ', '', get_option('valid_images'))));
     $fields->attach(form_input_upload(do_lang_tempcode('_WATERMARK', do_lang_tempcode('BOTTOM_RIGHT')), do_lang_tempcode('_DESCRIPTION_WATERMARK', do_lang_tempcode('BOTTOM_RIGHT')), 'watermark_bottom_right', false, $watermark_bottom_right, NULL, true, str_replace(' ', '', get_option('valid_images'))));
     $hidden = new ocp_tempcode();
     handle_max_file_size($hidden, 'image');
     require_code('feedback2');
     $fields->attach(feedback_fields($allow_rating == 1, $allow_comments == 1, NULL, false, $notes, $allow_comments == 2, true));
     // Permissions
     $fields->attach($this->get_permission_fields($name, NULL, $name == ''));
     return array($fields, $hidden);
 }
Esempio n. 5
0
 /**
  * Get form inputter.
  *
  * @param  string			The field name
  * @param  string			The field description
  * @param  array			The field details
  * @param  ?string		The actual current value of the field (NULL: none)
  * @return ?tempcode		The Tempcode for the input field (NULL: skip the field - it's not input)
  */
 function get_field_inputter($_cf_name, $_cf_description, $field, $actual_value)
 {
     $default = $field['cf_default'];
     $list = explode('|', $default);
     $_list = array();
     $exploded = explode(chr(10), $actual_value);
     foreach ($list as $i => $l) {
         $_list[] = array($l, 'field_' . strval($field['id']) . '_' . strval($i), in_array($l, $exploded), '');
     }
     return form_input_various_ticks($_list, $_cf_description, NULL, $_cf_name);
 }
Esempio n. 6
0
/**
 * 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'));
}
Esempio n. 7
0
 function form()
 {
     $title = get_page_title('REPORT_CONTENT');
     require_code('form_templates');
     $url = get_param('url', false, true);
     $content_type = get_param('content_type');
     // Equates to a content_meta_aware hook
     $content_id = get_param('content_id');
     require_code('content');
     if (!is_null($GLOBALS['SITE_DB']->query_value_null_ok('reported_content', 'r_counts', array('r_session_id' => get_session_id(), 'r_content_type' => $content_type, 'r_content_id' => $content_id)))) {
         warn_exit(do_lang_tempcode('ALREADY_REPORTED_CONTENT'));
     }
     list($content_title, $poster_id, ) = content_get_details($content_type, $content_id);
     if ($content_title == '') {
         $content_title = $content_type . ' #' . $content_id;
     }
     $poster = $GLOBALS['FORUM_DRIVER']->get_username($poster_id);
     // Show form with input field and CAPTCHA, like forum's report post...
     $member = $poster;
     if (!is_guest($poster_id)) {
         $member = '[page type="view" id="' . strval($poster_id) . '" param="' . get_module_zone('members') . '" caption="' . $poster . '"]members[/page]';
     }
     $hidden_fields = build_keep_form_fields('', true);
     $text = paragraph(do_lang_tempcode('DESCRIPTION_REPORT_CONTENT', escape_html($content_title), escape_html(integer_format(intval(get_option('reported_times'))))));
     $specialisation = new ocp_tempcode();
     if (!is_guest()) {
         $options = array();
         if (get_option('is_on_anonymous_posts') == '1') {
             $options[] = array(do_lang_tempcode('_MAKE_ANONYMOUS_POST'), 'anonymous', false, do_lang_tempcode('MAKE_ANONYMOUS_POST_DESCRIPTION'));
         }
         $specialisation = form_input_various_ticks($options, '');
     } else {
         $specialisation = new ocp_tempcode();
     }
     if (addon_installed('captcha')) {
         require_code('captcha');
         if (use_captcha()) {
             $specialisation->attach(form_input_captcha());
             $text->attach(paragraph(do_lang_tempcode('FORM_TIME_SECURITY')));
         }
     }
     if (addon_installed('points')) {
         $login_url = build_url(array('page' => 'login', 'type' => 'misc', 'redirect' => get_self_url(true, true)), get_module_zone('login'));
         $_login_url = escape_html($login_url->evaluate());
         if (is_guest() && (get_forum_type() != 'ocf' || has_actual_page_access(get_member(), 'join'))) {
             $text->attach(paragraph(do_lang_tempcode('NOT_LOGGED_IN_NO_CREDIT', $_login_url)));
         }
     }
     $post_url = build_url(array('page' => '_SELF', 'type' => 'actual'), '_SELF');
     $post = do_template('REPORTED_CONTENT_FCOMCODE', array('URL' => $url, 'CONTENT_ID' => $content_id, 'MEMBER' => $member, 'CONTENT_TITLE' => $content_title, 'POSTER' => $poster));
     $posting_form = get_posting_form(do_lang('REPORT_CONTENT'), $post->evaluate(), $post_url, $hidden_fields, $specialisation, NULL, '', NULL, NULL, NULL, NULL, true, false);
     return do_template('POSTING_SCREEN', array('TITLE' => $title, 'JAVASCRIPT' => function_exists('captcha_ajax_check') ? captcha_ajax_check() : '', 'TEXT' => $text, 'POSTING_FORM' => $posting_form));
 }
Esempio n. 8
0
/**
 * Get quiz data for exporting it as csv
 *
 * @param	array			The quiz questions
 * @return	tempcode		The rendered quiz	
 */
function render_quiz($questions)
{
    require_code('form_templates');
    // Sort out qa input
    $fields = new ocp_tempcode();
    foreach ($questions as $i => $question) {
        $name = 'q_' . strval($question['id']);
        $text = protect_from_escaping(is_string($question['q_question_text']) ? comcode_to_tempcode($question['q_question_text']) : get_translated_tempcode($question['q_question_text']));
        //$pretty_name=do_lang_tempcode('Q_NUM',integer_format($i+1));
        if ($question['q_num_choosable_answers'] == 0) {
            if ($question['q_long_input_field'] == 1) {
                $fields->attach(form_input_text($text, '', $name, '', $question['q_required'] == 1));
            } else {
                $fields->attach(form_input_line($text, '', $name, '', $question['q_required'] == 1));
            }
        } elseif ($question['q_num_choosable_answers'] > 1) {
            $content = array();
            foreach ($question['answers'] as $a) {
                $content[] = array(protect_from_escaping(is_string($a['q_answer_text']) ? comcode_to_tempcode($a['q_answer_text']) : get_translated_tempcode($a['q_answer_text'])), $name . '_' . strval($a['id']), false, '');
            }
            $fields->attach(form_input_various_ticks($content, '', NULL, $text, true));
        } else {
            $radios = new ocp_tempcode();
            foreach ($question['answers'] as $a) {
                $answer_text = is_string($a['q_answer_text']) ? comcode_to_tempcode($a['q_answer_text']) : get_translated_tempcode($a['q_answer_text']);
                $radios->attach(form_input_radio_entry($name, strval($a['id']), false, protect_from_escaping($answer_text)));
            }
            $fields->attach(form_input_radio($text, '', $name, $radios, $question['q_required'] == 1));
        }
    }
    return $fields;
}