[Phpslash-commit] CVS: phpslash-ft/class Author.class,1.46,1.47 Block_admin.class,1.10,1.11 Section.
Brought to you by:
joestewart,
nhruby
From: Joe S. <joe...@us...> - 2003-04-14 17:43:33
|
Update of /cvsroot/phpslash/phpslash-ft/class In directory sc8-pr-cvs1:/tmp/cvs-serv6703/phpslash-ft/class Modified Files: Author.class Block_admin.class Section.class Story_admin.class functions.inc Log Message: displayOptions rewritten to be able to display different option types. Index: Author.class =================================================================== RCS file: /cvsroot/phpslash/phpslash-ft/class/Author.class,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -d -r1.46 -r1.47 *** Author.class 26 Mar 2003 18:14:37 -0000 1.46 --- Author.class 14 Apr 2003 17:42:55 -0000 1.47 *************** *** 574,578 **** } ! $this->author_templ = displayoptions('author', $this->author_templ, "newauthor", ''); return $this->author_templ->parse('OUT',array("newauthor")); --- 574,579 ---- } ! $options = displayOptions('author', $this->author_templ, "newauthor", ''); ! $this->author_templ->set_var('OPTIONS', $options); return $this->author_templ->parse('OUT',array("newauthor")); *************** *** 748,752 **** } } ! $this->author_templ = displayoptions('author', $this->author_templ, 'template', $temparray); return $this->author_templ->parse('OUT','template'); --- 749,755 ---- } } ! $options = displayOptions('author', $this->author_templ, 'template', $temparray); ! $this->author_templ->set_var('OPTIONS', $options); ! return $this->author_templ->parse('OUT','template'); *************** *** 836,840 **** $q = "SELECT DISTINCT author_id, author_name FROM psl_author "; ! if ( !$ary['mode'] == "all") { $q .= ", psl_story WHERE psl_story.user_id = psl_author.author_id "; --- 839,845 ---- $q = "SELECT DISTINCT author_id, author_name FROM psl_author "; ! if ( !is_array($ary) || ! !array_key_exists('mode', $ary) || ! (!$ary['mode'] == "all")) { $q .= ", psl_story WHERE psl_story.user_id = psl_author.author_id "; Index: Block_admin.class =================================================================== RCS file: /cvsroot/phpslash/phpslash-ft/class/Block_admin.class,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Block_admin.class 27 Mar 2003 15:03:23 -0000 1.10 --- Block_admin.class 14 Apr 2003 17:42:56 -0000 1.11 *************** *** 82,85 **** --- 82,88 ---- } + // get default options + $options = displayOptions('block', $this->templ, "newblock", ''); + /* display a blank form */ $this->templ->set_var(array( *************** *** 92,99 **** 'CACHE_DATA' => "", 'BLOCK_ID' => "", ! 'ORDERNUM' => "" )); - $this->templ = displayoptions('block', $this->templ, "newblock", ''); return $this->templ->parse('OUT',array("newblock")); --- 95,102 ---- 'CACHE_DATA' => "", 'BLOCK_ID' => "", ! 'ORDERNUM' => "", ! 'OPTIONS' => $options )); return $this->templ->parse('OUT',array("newblock")); *************** *** 111,114 **** --- 114,119 ---- function editBlock($id) { + $section_ary = array(); + $this->getBlock($id); *************** *** 173,177 **** reset($temparray); } ! $this->templ->set_var(array( 'TITLEBAR' => getTitlebar("100%", "Update a Block"), --- 178,185 ---- reset($temparray); } ! ! // get default and saved options ! $options = displayOptions('block', $this->templ, "editblock", $temparray); ! $this->templ->set_var(array( 'TITLEBAR' => getTitlebar("100%", "Update a Block"), *************** *** 183,190 **** 'CACHE_DATA' => $this->block_info["cache_data"], 'ORDERNUM' => $this->block_info["ordernum"], ! 'BLOCK_ID' => $id )); - - $this->templ = displayoptions('block', $this->templ, "editblock", $temparray); $output = $this->templ->parse('OUT',array("editblock")); --- 191,197 ---- 'CACHE_DATA' => $this->block_info["cache_data"], 'ORDERNUM' => $this->block_info["ordernum"], ! 'BLOCK_ID' => $id, ! 'OPTIONS' => $options )); $output = $this->templ->parse('OUT',array("editblock")); Index: Section.class =================================================================== RCS file: /cvsroot/phpslash/phpslash-ft/class/Section.class,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Section.class 23 Jan 2003 02:48:03 -0000 1.14 --- Section.class 14 Apr 2003 17:42:57 -0000 1.15 *************** *** 225,229 **** $this->sec_templ->set_var(array( ! 'TITLEBAR' => getTitlebar("100%","New Section"), 'ACTION_URL' => $this->psl['phpself'], 'SECTION_NAME' => "", --- 225,229 ---- $this->sec_templ->set_var(array( ! 'TITLEBAR' => getTitlebar("100%","New Section"), 'ACTION_URL' => $this->psl['phpself'], 'SECTION_NAME' => "", *************** *** 231,241 **** )); ! $this->sec_templ = displayoptions('section', $this->sec_templ, "newsection", ''); } else { ! $q = "SELECT * FROM psl_section ! WHERE section_id = '$ary[section_id]'"; $this->db->query($q); $this->db->next_record(); --- 231,242 ---- )); ! $options = displayOptions('section', $this->sec_templ, "newsection", ''); + } else { ! $q = "SELECT * FROM psl_section ! WHERE section_id = '$ary[section_id]'"; $this->db->query($q); $this->db->next_record(); *************** *** 243,248 **** $this->sec_templ->set_block("newsection","each_option", "options"); ! $this->sec_templ->set_var(array( ! 'TITLEBAR' => getTitlebar("100%","Edit Section"), 'SECTION_ID' => $this->db->Record['section_id'], 'SECTION_NAME' => $this->db->Record['section_name'], --- 244,249 ---- $this->sec_templ->set_block("newsection","each_option", "options"); ! $this->sec_templ->set_var(array( ! 'TITLEBAR' => getTitlebar("100%","Edit Section"), 'SECTION_ID' => $this->db->Record['section_id'], 'SECTION_NAME' => $this->db->Record['section_name'], *************** *** 250,260 **** )); ! // options ! $temparray = unserialize($this->db->Record['section_options']); if (is_array($temparray)) { reset($temparray); } ! $this->sec_templ = displayoptions('section', $this->sec_templ, "newsection", $temparray); } --- 251,262 ---- )); ! // options ! $temparray = unserialize($this->db->Record['section_options']); if (is_array($temparray)) { reset($temparray); } ! $options = displayOptions('section', $this->sec_templ, "newsection", $temparray); ! $this->sec_templ->set_var('OPTIONS', $options); } Index: Story_admin.class =================================================================== RCS file: /cvsroot/phpslash/phpslash-ft/class/Story_admin.class,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** Story_admin.class 11 Apr 2003 16:06:10 -0000 1.17 --- Story_admin.class 14 Apr 2003 17:42:58 -0000 1.18 *************** *** 694,698 **** } ! $this->template = displayOptions('story', $this->template, "newstory", ''); if ($ary['content'] == "plain") { --- 694,699 ---- } ! $options = displayOptions('story', $this->template, "newstory", ''); ! $this->template->set_var('OPTIONS', $options); if ($ary['content'] == "plain") { *************** *** 965,969 **** } } ! $this->template = displayOptions('story', $this->template, "newstory", $temparray); $description = sprintf( "%s (%s) added new story %s as userid %s", $this->auth->auth['uname'], $this->auth->auth['uid'], $story_id, $user_id); logwrite("Story Admin", $description); --- 966,972 ---- } } ! $options = displayOptions('story', $this->template, "newstory", ''); ! $this->template->set_var('OPTIONS', $options); ! $description = sprintf( "%s (%s) added new story %s as userid %s", $this->auth->auth['uname'], $this->auth->auth['uid'], $story_id, $user_id); logwrite("Story Admin", $description); Index: functions.inc =================================================================== RCS file: /cvsroot/phpslash/phpslash-ft/class/functions.inc,v retrieving revision 1.141 retrieving revision 1.142 diff -C2 -d -r1.141 -r1.142 *** functions.inc 9 Apr 2003 15:52:00 -0000 1.141 --- functions.inc 14 Apr 2003 17:42:58 -0000 1.142 *************** *** 844,849 **** $template->set_var(array( 'DELIMETER' => $delimeter, ! 'LINK' => "?author_id=" . $ary[author_id] . $section_link . $topic_link, ! 'NAME' => $ary[author] )); $template->parse ("crumb_block", "each_crumb", true); --- 844,849 ---- $template->set_var(array( 'DELIMETER' => $delimeter, ! 'LINK' => "?author_id=" . $ary['author_id'] . $section_link . $topic_link, ! 'NAME' => $ary['author'] )); $template->parse ("crumb_block", "each_crumb", true); *************** *** 1125,1129 **** $_PSL['lang'] = basename($new_lang); } ! } elseif( $_SERVER['HTTP_ACCEPT_LANGUAGE']) { // else try to get from browser $lang_ary = split( "[,;]", $_SERVER['HTTP_ACCEPT_LANGUAGE']); $i = 0; --- 1125,1129 ---- $_PSL['lang'] = basename($new_lang); } ! } elseif( array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) { // else try to get from browser $lang_ary = split( "[,;]", $_SERVER['HTTP_ACCEPT_LANGUAGE']); $i = 0; *************** *** 1185,1189 **** $templatedir = $templatedir . "/" . basename($new_lang); } ! } elseif( $_SERVER['HTTP_ACCEPT_LANGUAGE']) { // else attempt to get from browser $lang_ary = explode( ",", $_SERVER['HTTP_ACCEPT_LANGUAGE']); $i = 0; --- 1185,1189 ---- $templatedir = $templatedir . "/" . basename($new_lang); } ! } elseif( array_key_exists('HTTP_ACCEPT_LANGUAGE',$_SERVER)) { // else attempt to get from browser $lang_ary = explode( ",", $_SERVER['HTTP_ACCEPT_LANGUAGE']); $i = 0; *************** *** 1576,1622 **** * @return tpl_object */ ! function displayOptions($module, $tpl_object, $template, $options_ary) { global $_PSL; $default_options = "default_".$module."_options"; $optioncount = $module."_optioncount"; $optioncnt = 0; if(count($options_ary) == 0) { $options_ary = ''; } ! if(!empty($_PSL[$default_options])) { $optioncnt = count($_PSL[$default_options]); } ! $tpl_object->set_block($template,"each_default_option", "doptions"); for ($i =0; $i < $optioncnt; $i++) { if(is_array($options_ary)) { reset($options_ary); } $dname = $_PSL[$default_options][$i]['name']; $dvalue = $_PSL[$default_options][$i]['value']; if(is_array($options_ary) && array_key_exists($dname, $options_ary)) { $dvalue = $options_ary[$dname]; - $tpl_object->set_var(array( - 'DOPTION_NAME' => "optionname[]", - 'DOPTION_NAME_VAL' => $dname, - 'DOPTION_VALUE' => "optionval[]", - 'DOPTION_VALUE_VAL' => $dvalue - )); - unset($options_ary[$dname]); - } else { - $tpl_object->set_var(array( - 'DOPTION_NAME' => "optionname[]", - 'DOPTION_NAME_VAL' => $dname, - 'DOPTION_VALUE' => "optionval[]", - 'DOPTION_VALUE_VAL' => $dvalue - )); } $tpl_object->parse("doptions", "each_default_option", true); - } ! $tpl_object->set_block($template,"each_option", "options"); if (is_array($options_ary)) { reset($options_ary); --- 1576,1707 ---- * @return tpl_object */ ! ! function displayOptions($module, $tpl_object='', $template='', $options_ary) { global $_PSL; + $_PSL['debug'] = true; + + if(!is_object($tpl_object)) { + $tpl_object = pslNew('slashTemplate'); + } + // $tpl_object->debug = 7; + // set options template + $tpl_object->set_file('optionfile', 'optionTypes.tpl'); + + // which module's options? $default_options = "default_".$module."_options"; $optioncount = $module."_optioncount"; $optioncnt = 0; + // available default option types + $dtype_ary = array( 'text', + 'radio', + 'select'); + + // initialize array and count if(count($options_ary) == 0) { $options_ary = ''; } ! if(!empty($_PSL[$default_options])) { $optioncnt = count($_PSL[$default_options]); + // debug("optioncnt", $optioncnt); } ! ! // set default option type blocks ! foreach($dtype_ary as $key) { ! $tpl_object->set_block('optionfile',"type_".$key, "option".$key); ! // debug("set_block", "type_".$key); ! // debug("set_block", "option".$key); ! ! } ! ! // process default options for ($i =0; $i < $optioncnt; $i++) { + + if(is_array($options_ary)) { reset($options_ary); } + + // get data from default option array $dname = $_PSL[$default_options][$i]['name']; + $ddescription = $_PSL[$default_options][$i]['description']; $dvalue = $_PSL[$default_options][$i]['value']; + $dtype = $_PSL[$default_options][$i]['type']; + $dchoices = ''; + // debug("default_option", $_PSL[$default_options][$i]); + if(array_key_exists('choices', $_PSL[$default_options][$i])) { + $dchoices = $_PSL[$default_options][$i]['choices']; + } + // debug("varvals", $tpl_object->varvals); + // debug("varkeys", $tpl_object->varkeys); + + // debug("get_var", "option".$dtype); + $thistype = $tpl_object->get_var("type_".$dtype); + // debug("thistype", $thistype); + $tpl_object->set_var("optiontype", $thistype); + // $tpl_object->varvals['optiontype'] = $thistype; + // debug('optiontype',$tpl_object->varvals['optiontype'] ); + // set html form blocks + $tpl_object->set_block('optiontype',"each_default_selected", "dselected"); + $tpl_object->set_block('optiontype',"each_default_notselected", "dnotselected"); + $tpl_object->set_block('optiontype',"each_default_choice", "dchoices"); + $tpl_object->set_block('optiontype',"each_default_option", "doptions"); + + // is there a saved value for this option? if(is_array($options_ary) && array_key_exists($dname, $options_ary)) { + // yes - load the saved value $dvalue = $options_ary[$dname]; } + // debug("dvalue", $dvalue); + $tpl_object->set_var(array( + 'DOPTION_NAME' => "optionname[]", + 'DOPTION_NAME_VAL' => $dname, + 'DOPTION_DESCRIPTION' => pslgetText($ddescription) + )); + + // option choices + if(is_array($dchoices)) { + // choices available + reset($dchoices); + foreach($dchoices as $key => $value) { + $tpl_object->set_var(array( + 'DOPTION_VALUE' => "optionval[]", + 'DOPTION_VALUE_VAL' => $key, + 'DOPTION_VALUE_LABEL' => $value + )); + // selected or not + if($dvalue == $key ) { + $tpl_object->parse("dchoices", "each_default_selected", true); + } else { + $tpl_object->parse("dchoices", "each_default_notselected", true); + } + $tpl_object->parse("dchoices", "each_default_choice", true); + } + } else { + // no choices + $tpl_object->set_var(array( + 'DOPTION_VALUE' => "optionval[]", + 'DOPTION_VALUE_VAL' => $dvalue + )); + } + if(is_array($options_ary) && array_key_exists($dname, $options_ary)) { + // option processed - remove it from queue. + // debug("unset", $dname); + unset($options_ary[$dname]); + } + // debug("parse", $dname); $tpl_object->parse("doptions", "each_default_option", true); ! $tpl_object->set_var(array( ! 'selected' => '', ! 'notselected' => '', ! 'dchoices' => '' ! )); ! } ! ! $tpl_object->set_block('optiontype',"each_option", "options"); if (is_array($options_ary)) { reset($options_ary); *************** *** 1657,1662 **** $i++; } ! return $tpl_object; } // end of function displayOptions --- 1742,1749 ---- $i++; } + + $options = $tpl_object->parse('OUT', "optiontype"); ! return $options; } // end of function displayOptions |