Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Thu, Sep 18, 12:26 PM

in-portal

Index: branches/unlabeled/unlabeled-1.25.2/admin/include/sections.php
===================================================================
--- branches/unlabeled/unlabeled-1.25.2/admin/include/sections.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.25.2/admin/include/sections.php (revision 5438)
@@ -0,0 +1,677 @@
+<?php
+
+$sections = array();
+
+class clsSection
+{
+ var $m_sections;
+ var $m_name;
+ var $m_title;
+ var $m_path;
+ var $m_file;
+ var $m_icon;
+ var $m_icon_small;
+ var $m_icon_list;
+ var $m_child;
+ var $m_parent;
+ var $m_left;
+ var $m_right;
+ var $m_notree = 0;
+ var $m_notabs=0;
+ var $m_nonavbar=0;
+ var $m_notitle=0;
+ var $m_toolbar=0;
+ var $m_description = NULL;
+ var $m_onclick=NULL;
+ var $m_key;
+ var $m_bar_title;
+ var $m_bar_title_plain_text = "";
+
+ function clsSection()
+ {
+ /* constructor */
+ }
+
+ function Get($name)
+ {
+ $var = "m_" . $name;
+ return isset($this->$var) ? $this->$var : '';
+ }
+
+ function Set($name, $value)
+ {
+ if (is_array($name))
+ {
+ for ($i=0; $i<sizeof($name); $i++)
+ {
+ $var = "m_" . $name[$i];
+ $this->$var = $value[$i];
+ }
+ }
+ else
+ {
+ $var = "m_" . $name;
+ $this->$var = $value;
+ }
+ }
+
+ function IsJavaScriptLink()
+ {
+ $file = $this->Get('file');
+ if(!$file) return false;
+
+ return (substr($file, 0, 10) == 'javascript' || $file == '#') ? true : false;
+ }
+
+ function IconURL($large=1)
+ {
+ global $rootURL;
+
+ if($large==1)
+ {
+ $url = $rootURL.$this->Get("icon");
+ }
+ elseif($large==2)
+ {
+ $url = $rootURL.$this->Get("icon_list");
+ }
+ else
+ $url = $rootURL.$this->Get("icon_small");
+ return $url;
+ }
+
+ function IsKernel4Link() {
+ $path = $this->Get('path');
+ if(!$path) return false;
+
+ $file = $this->Get('file');
+
+ return ( strpos($path, 'index4.php') !== false || strpos($file, 'kernel4:') !== false) ? true : false;
+ }
+
+ function URL()
+ {
+ global $rootURL, $m_var_list_update;
+
+ if(!$this->IsJavaScriptLink())
+ {
+ $m_var_list_update['opener']='r';
+ if ( $this->IsKernel4Link() ) {
+ global $var_list_update;
+ $stack_t = isset($var_list_update['t']) ? $var_list_update['t'] : null;
+ $var_list_update['t'] = $this->Get('file');
+ $env = BuildEnv();
+ $url = $rootURL.$this->Get('path');
+ $url .= (strstr($url, '?') ? '&' : '?').'env='.$env;
+ if ($stack_t == null) {
+ unset($var_list_update['t']);
+ }
+ else {
+ $var_list_update['t'] = $stack_t;
+ }
+ return $url;
+ }
+ else {
+ $env = BuildEnv();
+ }
+
+ $url = $rootURL.$this->Get('path').$this->Get('file');
+ $url .= (strstr($url, '?') ? '&' : '?').'env='.$env;
+ }
+ else {
+ // never called (tested with all modules installed)
+ $url = $this->Get('file');
+ }
+ return $url;
+ }
+
+ /* functions to display navigation elements */
+ function tab($envar)
+ {
+ global $imagesURL;
+ $link = $this->URL();
+ if(!$this->IsJavaScriptLink())
+ {
+ if(!strstr($link,'env='))
+ $link .= '?'. $envar;
+ }
+ $onclick = $this->Get('onclick');
+ $caption = language($this->Get('name'));
+ if(strlen($this->Get('name')))
+ {
+ $o ="<!-- Tab: $caption -->
+ <td><table bgcolor=\"#009FF0\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" onclick=\"\">
+ <tr onclick=\"$onclick\">
+ <td bgcolor=\"#009FF0\"><img title=\"\" src=\"$imagesURL/tab_left.gif\" width=\"15\" height=\"23\"></td>
+ <td nowrap bgcolor=\"#009FF0\" background=\"$imagesURL/tab_back.gif\" align=\"center\">
+ <a href=\"$link\" class=\"tab2\" onClick=\"$onclick\">$caption</a><br>
+ </td>
+ <td bgcolor=\"#009FF0\"><img title=\"\" src=\"$imagesURL/tab_right.gif\" width=\"15\" height=\"23\"></td>
+ </tr>
+ </table></td>";
+ }
+ else
+ $o = '';
+ return $o;
+ }//Individual Tab
+
+ function active_tab()
+ {
+ global $imagesURL, $envar;
+
+ $link = $this->URL();
+ $onclick = $this->Get("onclick");
+ if(!$this->IsJavaScriptLink())
+ {
+ if(!strstr($link,"env="))
+ $link .= "?". $envar;
+ }
+
+ $caption = language($this->Get("name"));
+
+ if (strlen($caption)<=8)
+ $backgr = "$imagesURL/tab_active_back3.jpg";
+ else if (strlen($caption)<=20)
+ $backgr = "$imagesURL/tab_active_back2.jpg";
+ else
+ $backgr = "$imagesURL/tab_active_back.jpg";
+
+ $o = "<!-- Tab: $caption -->
+ <td><table bgcolor=\"#FFFB32\" background=\"$backgr\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr>
+ <td><img title=\"\" src=\"$imagesURL/tab_active_left.gif\" width=\"15\" height=\"23\"></td>
+ <td nowrap align=\"center\" background=\"$imagesURL/tab_active_back.gif\">
+ <a href=\"$link\" class=\"tab\" onClick=\"$onclick\">$caption</a><br>
+ </td>
+ <td><img title=\"\" src=\"$imagesURL/tab_active_right.gif\" width=\"15\" height=\"23\"></td></tr>
+ </table></td>";
+ return $o;
+ }//Active Tab
+} /*clsSection*/
+
+class clsSectionList
+{
+ var $sections;
+ // var $section;
+ var $current;
+
+ function clsSectionList()
+ {
+ $this->sections = array();
+ $this->current = "default";
+ }
+
+ function GetSection($section)
+ {
+ if (is_array($this->sections) && strlen($section)) {
+ if (array_key_exists($section, $this->sections)) {
+ return $this->sections[$section];
+ }
+ else {
+ return null;
+ }
+ }
+ else {
+ return null;
+ }
+ }
+
+ function SetCurrentSection($section)
+ {
+ $this->current = $section;
+ }
+
+ function GetCurrentSection()
+ {
+ $ret = $this->GetSection($this->current);
+ if(!is_object($ret))
+ $ret = $this->GetSection("default");
+ return $ret;
+ }
+
+
+ function SimpleSection($module, $section_name, $tab_phrase, $title_phrase, $path, $script, $child,$parent,$left,$right)
+ {
+ // simplified method to add sections
+ global $pathtoroot;
+ $sn = explode(':', $section_name);
+
+ if (substr($script, 0, 8) == 'kernel4:') {
+ $img_path = $sn[0].'/admin_templates/img/icons';
+ }
+ else {
+ $img_path = $module.'/admin/images/icons';
+ }
+
+ if (!$img_path) {
+
+ }
+ if( !isset($title_phrase) ) $title_phrase = $tab_phrase;
+
+ $this->AddSection( $section_name,$tab_phrase, $title_phrase,$path, $script,
+ $img_path.'/icon46_'.$sn[1].'.gif', $img_path.'/icon24_'.$sn[1].'.gif',
+ $child,$parent,$left,$right,0,'',1,null,null,null,$img_path.'/icon46_list_'.$sn[1].'.gif');
+ }
+
+ function AddSection($section,$name,$title,$path,$file,$icon,$icon_small, $child,$parent,$left,$right,
+ $notree=0,$onClick = "",$notabs=0,$nonavbar=0,$notitle=0,$toolbar=0,$icon_list="", $bar_title = "", $bar_title_plain_text = "")
+ {
+ if($file == "subitems.php")
+ $file .= "?section=$section";
+
+ $s = new clsSection();
+
+ $s->Set("name", $name);
+ $s->Set("title",$title);
+ $s->Set("path", $path);
+ $s->Set("file", $file);
+ $s->Set("icon", $icon);
+ $s->Set("icon_list", $icon_list);
+ $s->Set("icon_small", $icon_small);
+ $s->Set("child", $child);
+ $s->Set("parent", $parent);
+ $s->Set("left", $left);
+ $s->Set("right", $right);
+ $s->Set("notree", $notree);
+ $s->Set("notabs", $notabs);
+ $s->Set("nonavbar", $nonavbar);
+ $s->Set("notitle", $notitle);
+ $s->Set("toolbar", $toolbar);
+ $s->Set("description", NULL);
+ $s->Set("onclick", $onClick);
+ $s->Set("key",$section);
+ $s->Set("bar_title",$bar_title);
+ $s->Set("bar_title_plain_text", $bar_title_plain_text);
+
+ if($parent != NULL)
+ {
+ $p = $this->GetSection($parent);
+ if(is_object($p))
+ {
+ if(!strlen($p->Get("child")))
+ {
+ //echo "Setting child of $parent to $section<br>\n";
+ $p->Set("child", $section); //set the parent if none set!
+ $this->sections[$parent]=$p;
+ }
+ }
+ if(!strlen($left) && !strlen($right))
+ {
+ /* find first child w/ a null right value */
+ foreach($this->sections as $secname => $subsection)
+ {
+ if($subsection->Get("parent") == $parent)
+ {
+ if(!strlen($subsection->Get("right")))
+ {
+ $this->sections[$secname]->Set("right", $section);
+ $s->Set("left", $secname);
+ break;
+ }
+ }
+ }
+ }
+ }
+ $this->sections[$section]=$s;
+ }
+
+ function AddDescription($section,$desc)
+ {
+ $sec = $this->GetSection($section);
+ if(is_object($sec))
+ {
+ $sec->Set("description",$desc);
+ $this->sections[$section] = $sec;
+ }
+ }
+
+ function sectionURL($section)
+ {
+ return $this->sections[$section]->URL();
+ }
+
+ function SectionIconURL($section,$large=1)
+ {
+ return $this->sections[$section]->IconURL($large);
+ }
+
+ function BuildTree($element, $parent)
+ {
+ global $pathtoroot,$envar;
+ global $rootURL;
+
+ $org = $element;
+ $element = strtolower($element);
+ $j_el=str_replace("-","_",$element);
+ $j_el=str_replace(":","_",$j_el);
+ $j_par=str_replace("-","_",$parent);
+ $j_par=str_replace(":","_",$j_par);
+ $sec = $this->sections[$element];
+ if(is_object($sec))
+ {
+ $caption = $this->sections[$element]->Get("name");
+ if(strlen($caption)==0)
+ $caption = $this->sections[$element]->Get("title");
+ $caption = language($caption);
+ $child =$this->sections[$element]->Get("child");
+ $notree = "";
+ if( isset($this->sections[$child]) && is_object($this->sections[$child]) )
+ $notree = $this->sections[$child]->Get("notree");
+ if (($child == NULL) or ($notree==-1))
+ {
+ print 'var item = insDoc('.$j_par.', gLnk(0, "'.$caption.'", "'.$this->SectionURL($element).'", "return checkEditMode();"));'."\n";
+ print "item.iconSrc = '".$this->SectionIconURL($element,0)."';\n";
+ if($this->sections[$element]->Get("right")!=NULL)
+ $this->BuildTree($this->sections[$element]->Get("right"), $parent);
+
+ return;
+ }
+ if ($child != NULL && $notree !=-1)
+ { //print "$j_el = insFld($j_par, gFld(\"".$sections[$element]['name']."\"));\n";
+
+ print 'var '.$j_el.' = insFld('.$j_par.', gFld("'.$caption.'","'.$this->SectionURL($element).'", "return checkEditMode();"));'."\n";
+ print $j_el . ".iconSrc='".$this->SectionIconURL($element,0)."';\n";
+ if($this->sections[$element]->Get("right")!=NULL)
+ $this->BuildTree($this->sections[$element]->Get("right"), $parent);
+
+ $parent = $element;
+ $this->BuildTree($this->sections[$element]->Get("child"), $parent);
+
+ }
+ }
+ }
+
+
+
+
+
+
+
+ function page_title()
+ {
+ global $imagesURL,$adminURL, $objConfig;
+
+ $o = "";
+ $sec = $this->GetCurrentSection();
+ if($sec->Get("notitle")!="1")
+ {
+ $caption = $sec->Get("title");
+
+ if(strlen($caption)==0)
+ {
+ if(strlen($sec->Get("parent")))
+ {
+ $p = $this->GetSection($sec->Get("parent"));
+ if(is_object($p))
+ {
+ $caption = $p->Get("title");
+ $icon = $p->IconURL(1);
+ }
+ }
+ }
+ else
+ $icon = $sec->IconURL(1);
+ $logout_link = $adminURL."/index.php";
+ if(strlen($caption))
+ {
+ if($sec->Get("key")=="in-portal:root")
+ {
+ $caption = stripslashes( strip_tags( $objConfig->Get('Site_Name') ) );
+ }
+ else
+ {
+ $caption = admin_language($caption);
+ }
+ $bg_image = 'logo_bg.gif';
+ $replace_modules = Array('in-link','in-news','in-bulletin');
+ foreach($replace_modules as $r_module)
+ if( $this->IsModule($r_module) )
+ {
+ $bg_image = 'logo_bg_'.$r_module.'.gif';
+ break;
+ }
+
+ if( defined('REQUIRE_LAYER_HEADER') )
+ {
+
+ $o = "<DIV style='position:relative; z-Index: 1; background-color: #ffffff; padding-top:1px;'>
+ <div style='position:absolute; width:100%;top:0px;' align='right'>
+ <img src='".$imagesURL.'/'.$bg_image."'></div><img src='".$imagesURL."/spacer.gif' width=1 height=7>
+ <br><div style='z-Index:1; position:relative'>";
+ $o .= "<!-- ADMIN TITLE --><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">
+ <tr><td valign=\"top\" class=\"admintitle\" align=\"left\">
+ <img title=\"\" width=\"46\" height=\"46\" src=\"$icon\" align=\"absmiddle\">&nbsp;$caption<br>
+ <img src='".$imagesURL."/spacer.gif' width=1 height=4><br>
+ </td></tr></table>";
+ }
+ else
+ {
+ $o = '<!-- ADMIN TITLE -->
+ <!-- <DIV style="position:relative; z-Index: 1; background-color: #ffffff; padding-top:1px;"> -->
+ <table cellpadding="0" cellspacing="0" border="0" width="100%">
+ <tr>
+ <td valign="top" class="admintitle" align="left" style="background: url('.$imagesURL.'/'.$bg_image.') top right; background-repeat: no-repeat;">
+ <img title="" width="46" height="46" src="'.$icon.'" align="absmiddle">&nbsp;'.$caption.'<br>
+ <img src="'.$imagesURL.'/spacer.gif" width="1" height="4"><br>
+ </td>
+ </tr>
+ </table>
+ ';
+ }
+ }
+ }
+ return $o;
+ }
+
+ function IsModule($module_name)
+ {
+ // checks if there is requested module used in right frame
+
+ // module folder match
+ $url_split = explode('/', $_SERVER['PHP_SELF']);
+ if( in_array($module_name, $url_split) ) return 1;
+
+ // module section match
+ $section = GetVar('section');
+ if($section)
+ {
+ $section = explode(':', $section);
+ if( $section[0] == $module_name ) return true;
+ }
+ return false;
+ }
+
+ function page_tabs($envar)
+ {
+ $showtabs=0;
+ $o = '';
+ $sec = $this->GetCurrentSection();
+ if ($sec->Get("notabs")!=1)
+ {
+ //get starting node
+ $node = $sec;
+ while (strlen($node->Get("left")))
+ {
+ $node = $this->GetSection($node->Get("left"));
+ }
+ if($node)
+ {
+
+ $o = "<!-- TABS --><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\"><tr>
+ <td align=\"right\" width=\"100%\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" height=\"23\">
+ <tr>";
+ $showtabs=1;
+ }
+ //traverse and print tabs
+ while ( isset($node) && is_object($node) )
+ {
+ if ($node->Get("key") == $this->current)
+ $o .= $node->active_tab();
+ else
+ $o .= $node->tab($envar);
+
+ $right = $node->Get("right");
+ unset($node);
+ if(strlen($right))
+ $node = $this->GetSection($right);
+ }
+ if($showtabs)
+ {
+ $o .= "</tr></table></td></tr></table>";
+ }
+ }
+ return $o;
+ }
+
+ function section_header($envar,$navbar=NULL,$extra_title=NULL, $no_help = false, $OtherSection = '')
+ {
+ global $pathtoroot;
+ global $pathtolocal;
+ global $imagesURL;
+ global $adminURL;
+ global $objConfig;
+
+ $output = '';
+ $HelpIcon = $imagesURL."/blue_bar_help.gif";
+ $node = $this->GetCurrentSection();
+ if(is_object($node))
+ {
+ $helpURL = $adminURL.'/help/help.php?'.( substr($envar,0,3) == 'env' ? '' : 'env=').$envar.'&destform=popup';
+ $node_key = $node->Get('key');
+ $o = "<!-- SECTION NAVIGATOR -->";
+ //background="'.$imagesURL.'/tabnav_left.jpg"
+ if($no_help == false) $o .= '<form name="help_form" id="help_form" action="'.$helpURL.'" method="post"><input type="hidden" id="section" name="section" value=""></form>';
+ $o .= '<table border="0" cellpadding="2" cellspacing="0" class="tableborder_full" width="100%" height="30">';
+ $o .= '<tr><TD class="header_left_bg" width="100%">';
+
+ //get path up to the parent node
+ while( isset($node) && is_object($node) )
+ {
+ if( !strlen($extra_title) )
+ {
+ $bar_title = $node->Get("bar_title");
+ $bar_title_plain_text = $node->Get("bar_title_plain_text");
+
+ if(strlen($bar_title) && !is_null($bar_title))
+ $caption = language($bar_title);
+ elseif (is_null($bar_title))
+ $caption = "";
+ else
+ $caption = language($node->Get("name"));
+
+ if (strlen($bar_title_plain_text))
+ $caption.= $bar_title_plain_text;
+ }
+ else
+ {
+ $caption = $extra_title;
+ }
+
+ $output = '<span class="tablenav_link" id="bb_title">'.$caption.'</span><script language="javascript">set_window_title( document.getElementById("bb_title").innerHTML );</script>';
+ unset($node);
+ }
+
+ $o .= $output;
+ if(strlen($navbar))
+ $o .= "::<b>".$navbar."</b>";
+ if($OtherSection) $node_key = $OtherSection;
+ $o .= "</td><td align=\"right\" class=\"tablenav\" background=\"$imagesURL/tabnav_back.jpg\" width=\"10\">";
+ if($no_help == false) $o .= "<a class=\"link\" onclick=\"ShowHelp('".$node_key."');\"><img src=\"$HelpIcon\" border=\"0\"></A>";
+ $o .= "</td></tr></table><!-- END SECTION NAVIGATOR -->";
+ }
+ return $o;
+ }
+
+} /* clsSectionList */
+
+$objSections = new clsSectionList();
+$objSections->AddSection("in-portal:root", $objConfig->Get('Site_Name'), $objConfig->Get('Site_Name'), $admin."/","subitems.php",
+$admin."/icons/icon46_site.gif", $admin."/icons/icon24_site.gif",
+"in-portal:site", NULL, NULL,"in-portal:users",0,"",1, NULL,NULL,NULL, "", "la_section_overview");
+
+$objSections->AddSection("in-portal:site", "la_tab_Site_Structure","la_title_Site_Structure", $admin."/","subitems.php",
+$admin."/icons/icon46_struct.gif", $admin."/icons/icon24_struct.gif",
+"in-portal:browse", "in-portal:root", NULL,"in-portal:users",0,"",1,NULL,NULL,NULL,$admin."/icons/icon46_list_struct.gif","la_selecting_categories");
+
+$objSections->AddSection("in-portal:users","la_tab_Community","la_title_Community",$admin."/","subitems.php",
+$admin."/icons/icon46_community.gif",$admin."/icons/icon24_community.gif", NULL,"in-portal:root","in-portal:site","in-portal:modules",0,"",1,NULL,NULL,NULL,$admin."/icons/icon46_list_community.gif","la_section_overview");
+
+$objSections->AddSection("in-portal:modules","la_tab_ModulesSettings","la_title_Settings",$admin."/","subitems.php",
+$admin."/icons/icon46_modules.gif",$admin."/icons/icon24_modules.gif",NULL, "in-portal:root","in-portal:users","in-portal:reports",0,"",1,NULL,NULL,NULL,$admin."/icons/icon46_list_modules.gif","la_section_overview");
+
+$objSections->AddSection("in-portal:mod_status","la_tab_Modules","la_title_Module_Status",$admin."/modules/","mod_status.php",
+$admin."/icons/icon46_modules.gif",$admin."/icons/icon24_modules.gif",NULL, NULL,NULL,NULL,0,"",1,NULL,NULL,NULL,$admin."/icons/icon46_list_modules.gif");
+
+$objSections->AddSection("in-portal:addmodule","la_tab_Modules","la_title_Add_Module",$admin."/modules/","addmodule.php",
+$admin."/icons/icon46_modules.gif",$admin."/icons/icon24_modules.gif",NULL, NULL,NULL,NULL,0,"",1,NULL,NULL,NULL,$admin."/icons/icon46_list_modules.gif");
+
+$objSections->AddSection("in-portal:reports","la_tab_Reports","la_title_Reports",$admin."/","subitems.php",
+$admin."/icons/icon46_summary_logs.gif",$admin."/icons/icon24_summary_logs.gif",NULL, "in-portal:root","in-portal:modules","in-portal:system",0,"",1,NULL,NULL,NULL,$admin."/icons/icon46_list_summary_logs.gif","la_section_overview");
+
+$objSections->AddSection("in-portal:log_summary","la_tab_Summary","la_tab_Summary",$admin."/logs/","summary.php",
+$admin."/icons/icon46_summary.gif",$admin."/icons/icon24_summary.gif",NULL,
+"in-portal:reports",NULL,"in-portal:searchlog",0,"",1,NULL,NULL,NULL,$admin."/icons/icon46_list_summary.gif");
+
+$objSections->AddSection("in-portal:searchlog","la_tab_SearchLog","la_tab_SearchLog",$admin."/logs/","searchlog.php",
+$admin."/icons/icon46_search_log.gif",$admin."/icons/icon24_search_log.gif",
+NULL,"in-portal:reports","in-portal:log_summary","in-portal:sessionlog",0,"",1,NULL,NULL,NULL,$admin."/icons/icon46_list_search_log.gif");
+
+$objSections->AddSection("in-portal:sessionlog","la_tab_SessionLog","la_tab_SessionLog",$admin."/logs/","session_list.php",
+$admin."/icons/icon46_sessions_log.gif",$admin."/icons/icon24_sessions_log.gif",
+NULL,"in-portal:reports","in-portal:sessionlog",'in-portal:emaillog',0,"",1,NULL,NULL,NULL,$admin."/icons/icon46_list_sessions_log.gif");
+
+$objSections->AddSection("in-portal:emaillog","la_tab_EmailLog","la_tab_EmailLog",$admin."/logs/","email_log.php",
+$admin."/icons/icon46_email_log.gif",$admin."/icons/icon24_email_log.gif",
+NULL,"in-portal:reports","in-portal:emaillog",NULL,0,"",1,NULL,NULL,NULL,$admin."/icons/icon46_list_email_log.gif");
+
+/* Help */
+$objSections->AddSection("in-portal:help","la_tab_Help","la_title_Help",$admin."/help/","manual.pdf",
+$admin."/icons/icon46_help.gif",$admin."/icons/icon24_help.gif",
+NULL,"in-portal:root","in-portal:system",NULL,0,"",1,NULL,NULL,NULL,$admin."/icons/icon46_list_help.gif");
+
+
+/*
+$objSections->AddSection("in-portal:help","la_tab_Help","la_title_Help",$admin."/help/topics/","download.html",
+$admin."/icons/icon46_help.gif",$admin."/icons/icon24_help.gif",
+NULL,"in-portal:root","in-portal:system",NULL,0,"",1,NULL,NULL,NULL,$admin."/icons/icon46_list_help.gif");
+
+$objSections->AddSection("in-portal:help_overview","la_tab_Overview","la_title_Help",$admin."/help/","help.php",
+$admin."/icons/icon46_help.gif",$admin."/icons/icon24_help.gif",
+NULL,"in-portal:help",NULL,"in-portal:help_ch1",NULL,NULL,NULL,NULL,NULL,NULL,$admin."/icons/icon46_list_help.gif");
+$objSections->AddSection("in-portal:help_ch1","Chapter 1","Chapter 1",$admin."/help/","help.php",
+$admin."/icons/icon46_help.gif",$admin."/icons/icon24_help.gif",
+NULL,"inportal:help","in-portal:help_overview","in-portal:help_ch2");
+$objSections->AddSection("in-portal:help_ch2","Chapter 2","Chapter 2",$admin."/help/","help.php",
+$admin."/icons/icon46_help.gif",$admin."/icons/icon24_help.gif",
+NULL,"inportal:help","in-portal:help_ch1",NULL);
+*/
+/* Help ends */
+$objSections->AddSection("in-portal:item_select","la_title_Select_Item","Select Item",$admin."/","item_select.php","","",
+NULL,NULL,NULL,0,"",1,1);
+
+$objSections->AddSection("in-portal:rel_select","la_title_Select_Target_Item","Select Item",$admin."/","rel_select.php","","",
+NULL,NULL,NULL,0,"",1,0,1,1);
+
+$NewButtons = array();
+/* each module will add to the array declared below, which contains the info for the
+'new' button for the module's Browse data. The array is an array of arrays,
+and the subarray should contain the following indexes:
+
+ImagePath = URL to the directory containing the image
+Action = Action attribute of the image (this is also the "base name" of the image
+Alt = Image ALT value
+Tab = If set, button will only be displayed when this div is active
+
+*/
+
+$m = GetModuleArray("admin");
+if(is_array($m))
+{
+ foreach($m as $key=>$value)
+ {
+ $mod = $pathtoroot . $value . "admin/include/navmenu.php";
+ include_once($mod);
+ }
+}
+$objSections->AddSection("default","","",$admin."/","#",NULL,NULL,NULL,NULL,NULL,NULL);
+
+?>
Property changes on: branches/unlabeled/unlabeled-1.25.2/admin/include/sections.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.25
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.25.2/admin/advanced_view.php
===================================================================
--- branches/unlabeled/unlabeled-1.25.2/admin/advanced_view.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.25.2/admin/advanced_view.php (revision 5438)
@@ -0,0 +1,311 @@
+<?php
+##############################################################
+##In-portal ##
+##############################################################
+## In-portal ##
+## Intechnic Corporation ##
+## All Rights Reserved, 1998-2002 ##
+## ##
+## No portion of this code may be copied, reproduced or ##
+## otherwise redistributed without proper written ##
+## consent of Intechnic Corporation. Violation will ##
+## result in revocation of the license and support ##
+## privileges along maximum prosecution allowed by law. ##
+##############################################################
+
+function k4getmicrotime()
+{
+ list($usec, $sec) = explode(" ", microtime());
+ return ((float)$usec + (float)$sec);
+}
+
+$start = k4getmicrotime();
+define('ADVANCED_VIEW', 1);
+
+// new startup: begin
+define('REL_PATH', 'admin');
+$relation_level = count( explode('/', REL_PATH) );
+define('FULL_PATH', realpath(dirname(__FILE__) . str_repeat('/..', $relation_level) ) );
+require_once FULL_PATH.'/kernel/startup.php';
+// new startup: end
+
+checkViewPermission('in-portal:advanced_view');
+define('REQUIRE_LAYER_HEADER', 1);
+$b_topmargin = "0";
+//$b_header_addon = "<DIV style='position:relative; z-Index: 1; background-color: #ffffff; padding-top:1px;'><div style='position:absolute; width:100%;top:0px;' align='right'><img src='images/logo_bg.gif'></div><img src='images/spacer.gif' width=1 height=15><br><div style='z-Index:1; position:relative'>";
+
+require_login();
+
+$indexURL = $rootURL."index.php";
+$homeURL = "javascript:AdminCatNav('".$_SERVER["PHP_SELF"]."?env=".BuildEnv()."');";
+
+$m_var_list_update["cat"] = 0;
+unset($m_var_list_update["cat"]);
+
+$pathtolocal = $pathtoroot."kernel/";
+require_once ($pathtoroot.$admin."/include/elements.php");
+//require_once ($pathtoroot."kernel/admin/include/navmenu.php");
+require_once ($pathtolocal."admin/include/navmenu.php");
+require_once($pathtoroot.$admin."/browse/toolbar.php");
+
+$mod_prefixes = Array();
+$m = GetModuleArray();
+foreach($m as $key=>$value)
+{
+ $path = $pathtoroot.$value."admin/include/parser.php";
+ if(file_exists($path))
+ {
+ //echo "<!-- $path -->";
+ $mod_prefixes[] = $key;
+ @include_once($path);
+ }
+}
+
+$application->InitParser();
+
+$cat_templates = $objModules->ExecuteFunction('GetModuleInfo', 'advanced_view_template');
+foreach ($cat_templates as $a_mod => $a_template) {
+ if (!$a_template) continue;
+ $a_var = $a_mod.'_TAB_HTML';
+ $$a_var = $application->ParseBlock(Array('name'=>$a_template), 0, true);
+}
+
+if (!defined('IS_INSTALL') ) define('IS_INSTALL', 0);
+if( !IS_INSTALL ) require_login();
+
+//Set Section
+$section = 'in-portal:advanced_view';
+
+//Set Environment Variable
+
+// save last category visited
+$objSession->SetVariable('prev_category', $objSession->GetVariable('last_category') );
+$objSession->SetVariable('last_category', $objCatList->CurrentCategoryID() );
+
+$objSession->SetVariable("HasChanges", 0);
+// where should all edit popups submit changes
+$objSession->SetVariable("ReturnScript", basename($_SERVER['PHP_SELF']) );
+
+
+// common "Advanced View" tab php functions: begin
+function GetAdvView_SearchWord($prefix)
+{
+ global $objSession;
+ return $objSession->GetVariable($prefix.'_adv_view_search');
+}
+
+function SaveAdvView_SearchWord($prefix)
+{
+ global $objSession;
+ $SearchWord = $objSession->GetVariable($prefix.'_adv_view_search');
+ if( isset($_REQUEST['SearchWord']) )
+ {
+ $SearchWord = $_REQUEST['SearchWord'];
+ $objSession->SetVariable($prefix.'_adv_view_search', $SearchWord);
+ }
+}
+
+function ResetAdvView_SearchWord($prefix)
+{
+ global $objSession;
+ $objSession->SetVariable($prefix.'_adv_view_search', '');
+}
+
+function ShowSearchForm($prefix, $envar, $TabID)
+{
+ global $imagesURL;
+ $btn_prefix = $imagesURL.'/toolbar/icon16_search';
+ $SearchWord = GetAdvView_SearchWord($prefix);
+ echo '<form method="post" action="'.$_SERVER["PHP_SELF"].'?'.$envar.'" name="'.$prefix.'_adv_view_search" id="'.$prefix.'_adv_view_search">
+ <input type="hidden" name="Action" value="">
+ <table cellspacing="0" cellpadding="0">
+ <tr>
+ <td>'.admin_language('la_SearchLabel').'&nbsp;</td>
+ <td><input id="'.$prefix.'_SearchWord" type="text" value="'.inp_htmlize($SearchWord,1).'" name="SearchWord" size="10" style="border-width: 1; border-style: solid; border-color: 999999"></td>
+ <td>
+ <img
+ id="'.$TabID.'_imgSearch"
+ src="'.$btn_prefix.'.gif"
+ title="'.admin_language("la_ToolTip_Search").'"
+ align="absMiddle"
+ onclick="SubmitSearch(\''.$prefix.'_adv_view_search\',\''.$prefix.'_adv_view_search\');"
+ onmouseover="this.src=\''.$btn_prefix.'_f2.gif\'"
+ onmouseout="this.src=\''.$btn_prefix.'.gif\'"
+ style="cursor:hand"
+ width="22"
+ height="22"
+ >
+ <img
+ id="imgSearchReset"
+ src="'.$btn_prefix.'_reset.gif"
+ title="'.admin_language("la_ToolTip_Search").'"
+ align="absMiddle"
+ onclick="SubmitSearch(\''.$prefix.'_adv_view_search\',\''.$prefix.'_adv_view_search_reset\');"
+ onmouseover="this.src=\''.$btn_prefix.'_reset_f2.gif\'"
+ onmouseout="this.src=\''.$btn_prefix.'_reset.gif\'"
+ style="cursor:hand"
+ width="22"
+ height="22"
+ >&nbsp;
+
+
+ </td>
+ </tr>
+ </table>
+ </form>
+ <script language="javascript">
+ document.getElementById("'.$prefix.'_SearchWord").onkeydown = getKey;
+ </script>
+
+ ';
+}
+// common "Advanced View" tab php functions: end
+
+/* page header */
+$charset = GetRegionalOption('Charset');
+print <<<END
+<html>
+<head>
+ <title>In-portal</title>
+ <meta http-equiv="content-type" content="text/html;charset=$charset">
+ <meta http-equiv="Pragma" content="no-cache">
+ <script language="JavaScript">
+ imagesPath='$imagesURL'+'/';
+ </script>
+
+END;
+
+ require_once($pathtoroot.$admin."/include/mainscript.php");
+
+print <<<END
+<script type="text/javascript">
+ if (window.opener != null) {
+ theMainScript.CloseAndRefreshParent();
+ }
+</script>
+END;
+
+print <<<END
+ <script src="$browseURL/toolbar.js"></script>
+ <script src="$browseURL/checkboxes_new.js"></script>
+ <!-- <script language="JavaScript1.2" src="$browseURL/fw_menu.js"></script> -->
+ <link rel="stylesheet" type="text/css" href="$browseURL/checkboxes.css">
+ <link rel="stylesheet" type="text/css" href="$cssURL/style.css">
+ <link rel="stylesheet" type="text/css" href="$browseURL/toolbar.css">
+END;
+load_module_styles();
+if( !isset($list) ) $list = '';
+
+int_SectionHeader();
+
+ $filter = false;
+ $bit_combo = $objModules->ExecuteFunction('GetModuleInfo', 'all_bitmask');
+ $bit_combo = $objModules->MergeReturn($bit_combo);
+ foreach($bit_combo['VarName'] as $mod_name => $VarName)
+ {
+ //echo "VarName: [$VarName] = [".$objConfig->Get($VarName)."], ALL = [".$bit_combo['Bits'][$mod_name]."]<br>";
+ if( $objConfig->Get($VarName) )
+ if( $objConfig->Get($VarName) != $bit_combo['Bits'][$mod_name] )
+ {
+ $filter = true;
+ break;
+ }
+ }
+
+?>
+</div>
+<!-- alex mark -->
+<table class="toolbar" height="30" cellspacing="0" cellpadding="0" width="100%" border="0">
+ <tbody>
+ <tr>
+ <td>
+ <div name="toolBar" id="mainToolBar">
+ <tb:button action="edit" title="<?php echo admin_language("la_ToolTip_Edit"); ?>" ImagePath="<?php echo $imagesURL."/toolbar/";?>">
+ <tb:button action="delete" title="<?php echo admin_language("la_ToolTip_Delete"); ?>" ImagePath="<?php echo $imagesURL."/toolbar/";?>">
+ <tb:separator ImagePath="<?php echo $imagesURL."/toolbar/";?>">
+ <tb:button action="approve" title="<?php echo admin_language("la_ToolTip_Approve"); ?>" ImagePath="<?php echo $imagesURL."/toolbar/";?>">
+ <tb:button action="decline" title="<?php echo admin_language("la_ToolTip_Decline"); ?>" ImagePath="<?php echo $imagesURL."/toolbar/";?>">
+ <tb:separator ImagePath="<?php echo $imagesURL."/toolbar/";?>">
+ <tb:button action="print" title="<?php echo admin_language("la_ToolTip_Print"); ?>" ImagePath="<?php echo $imagesURL."/toolbar/";?>">
+ <tb:button action="view" title="<?php echo admin_language("la_ToolTip_View"); ?>" ImagePath="<?php echo $imagesURL."/toolbar/";?>">
+ </div>
+ </td>
+ </tr>
+ </tbody>
+</table>
+
+<?php if ($filter) { ?>
+<table width="100%" border="0" cellspacing="0" cellpadding="0" class="toolbar">
+ <tr>
+ <td valign="top">
+ <?php int_hint_red(admin_language("la_Warning_Filter")); ?>
+ </td>
+ </tr>
+</table>
+<?php } ?>
+<br>
+ <!-- CATEGORY DIVIDER -->
+
+</DIV>
+</div>
+<DIV style="background-color: #ffffff; position: relative; padding-top: 1px; top: -1px; z-Index:0" id="firstContainer">
+ <DIV style="background-color: #ffffff; position: relative; padding-top: 1px; top: -1px; z-Index:2" id="secondContainer">
+
+
+
+ <?php
+
+ print $ItemTabs->TabRow();
+
+ if(count($ItemTabs->Tabs))
+ {
+ ?>
+ <div class="divider" id="tabsDevider"><img width=1 height=1 src="images/spacer.gif"></div>
+ <?php
+ }
+ ?>
+ </DIV>
+
+ <?php
+ unset($m);
+ $m = GetModuleArray("admin");
+
+
+ foreach($m as $key=>$value)
+ {
+ $path = $pathtoroot.$value."admin/advanced_view.php";
+ //echo "Including File: $path<br>";
+ if(file_exists($path))
+ {
+ //echo "\n<!-- $path -->\n";
+ include_once($path);
+ }
+ }
+ $admin = $objConfig->Get("AdminDirectory");
+ if(!strlen($admin)) $admin = "admin";
+ ?>
+ <form method="post" action="<?php echo $rootURL.$admin; ?>/advanced_view.php?env=<?php echo BuildEnv(); ?>" name="viewmenu">
+ <input type="hidden" name="fieldname" value="">
+ <input type="hidden" name="varvalue" value="">
+ <input type="hidden" name="varvalue2" value="">
+ <input type="hidden" name="Action" value="">
+ </form>
+</DIV>
+<!-- END CODE-->
+<script language="JavaScript">
+ InitPage();
+ if(default_tab.length == 0)
+ {
+ cookie_start = theMainScript.GetCookie('active_tab');
+ if (cookie_start != null) start_tab = cookie_start;
+ if(start_tab!=null) toggleTabB(start_tab, true);
+ }
+ else
+ {
+ toggleTabB(default_tab,true);
+ }
+</script>
+<?php
+ $objSession->SetVariable("HasChanges", 0);
+ int_footer();
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.25.2/admin/advanced_view.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.25
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.25.2/core/kernel/utility/temp_handler.php
===================================================================
--- branches/unlabeled/unlabeled-1.25.2/core/kernel/utility/temp_handler.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.25.2/core/kernel/utility/temp_handler.php (revision 5438)
@@ -0,0 +1,657 @@
+<?php
+
+class kTempTablesHandler extends kBase {
+ var $Tables = Array();
+
+ /**
+ * Master table name for temp handler
+ *
+ * @var string
+ * @access private
+ */
+ var $MasterTable = '';
+
+ /**
+ * IDs from master table
+ *
+ * @var Array
+ * @access private
+ */
+ var $MasterIDs = Array();
+
+ var $AlreadyProcessed = Array();
+
+ var $DroppedTables = Array();
+
+ var $FinalRefs = Array();
+
+ var $CopiedTables = Array();
+
+
+ /**
+ * IDs of newly cloned items (key - prefix.special, value - array of ids)
+ *
+ * @var Array
+ */
+ var $savedIDs = Array();
+
+ /**
+ * Description
+ *
+ * @var kDBConnection
+ * @access public
+ */
+ var $Conn;
+
+ function kTempTablesHandler()
+ {
+ parent::kBase();
+ $this->Conn =& $this->Application->GetADODBConnection();
+ }
+
+ function SetTables($tables)
+ {
+ // set tablename as key for tables array
+ $ret = Array();
+ $this->Tables = $tables;
+ $this->MasterTable = $tables['TableName'];
+ }
+
+ function saveID($prefix, $special = '', $id = null)
+ {
+ $this->savedIDs[$prefix.($special ? '.' : '').$special][] = $id;
+ }
+
+ /**
+ * Get temp table name
+ *
+ * @param string $table
+ * @return string
+ */
+ function GetTempName($table)
+ {
+ return $this->Application->GetTempName($table);
+ }
+
+ function GetTempTablePrefix()
+ {
+ return $this->Application->GetTempTablePrefix();
+ }
+
+ /**
+ * Return live table name based on temp table name
+ *
+ * @param string $temp_table
+ * @return string
+ */
+ function GetLiveName($temp_table)
+ {
+ return $this->Application->GetLiveName($temp_table);
+ }
+
+ function IsTempTable($table)
+ {
+ return $this->Application->IsTempTable($table);
+ }
+
+ /**
+ * Return temporary table name for master table
+ *
+ * @return string
+ * @access public
+ */
+ function GetMasterTempName()
+ {
+ return $this->GetTempName($this->MasterTable);
+ }
+
+ function CreateTempTable($table)
+ {
+ $query = sprintf("CREATE TABLE %s SELECT * FROM %s WHERE 0",
+ $this->GetTempName($table),
+ $table);
+
+ $this->Conn->Query($query);
+ }
+
+ function BuildTables($prefix, $ids)
+ {
+ $this->TableIdCounter = 0;
+ $tables = Array(
+ 'TableName' => $this->Application->getUnitOption($prefix, 'TableName'),
+ 'IdField' => $this->Application->getUnitOption($prefix, 'IDField'),
+ 'IDs' => $ids,
+ 'Prefix' => $prefix,
+ 'TableId' => $this->TableIdCounter++,
+ );
+
+ $parent_prefix = $this->Application->getUnitOption($prefix, 'ParentPrefix');
+ if ($parent_prefix) {
+ $tables['ForeignKey'] = $this->Application->getUnitOption($prefix, 'ForeignKey');
+ $tables['ParentPrefix'] = $parent_prefix;
+ $tables['ParentTableKey'] = $this->Application->getUnitOption($prefix, 'ParentTableKey');
+ }
+
+ $this->FinalRefs[ $tables['TableName'] ] = $tables['TableId']; // don't forget to add main table to FinalRefs too
+
+ $SubItems = $this->Application->getUnitOption($prefix,'SubItems');
+ if (is_array($SubItems)) {
+ foreach ($SubItems as $prefix) {
+ $this->AddTables($prefix, $tables);
+ }
+ }
+ $this->SetTables($tables);
+ }
+
+ function AddTables($prefix, &$tables)
+ {
+ $tmp = Array(
+ 'TableName' => $this->Application->getUnitOption($prefix,'TableName'),
+ 'IdField' => $this->Application->getUnitOption($prefix,'IDField'),
+ 'ForeignKey' => $this->Application->getUnitOption($prefix,'ForeignKey'),
+ 'ParentPrefix' => $this->Application->getUnitOption($prefix, 'ParentPrefix'),
+ 'ParentTableKey' => $this->Application->getUnitOption($prefix,'ParentTableKey'),
+ 'Prefix' => $prefix,
+ 'AutoClone' => $this->Application->getUnitOption($prefix,'AutoClone'),
+ 'AutoDelete' => $this->Application->getUnitOption($prefix,'AutoDelete'),
+ 'TableId' => $this->TableIdCounter++,
+ );
+
+ $this->FinalRefs[ $tmp['TableName'] ] = $tmp['TableId'];
+
+ $constrain = $this->Application->getUnitOption($prefix,'Constrain');
+ if ($constrain)
+ {
+ $tmp['Constrain'] = $constrain;
+ $this->FinalRefs[ $tmp['TableName'].$tmp['Constrain'] ] = $tmp['TableId'];
+ }
+
+ $SubItems = $this->Application->getUnitOption($prefix,'SubItems');
+ $same_sub_counter = 1;
+ if( is_array($SubItems) )
+ {
+ foreach($SubItems as $prefix)
+ {
+ $this->AddTables($prefix, $tmp);
+ }
+ }
+
+ if ( !is_array(getArrayValue($tables, 'SubTables')) ) {
+ $tables['SubTables'] = array();
+ }
+
+ $tables['SubTables'][] = $tmp;
+ }
+
+ function CloneItems($prefix, $special, $ids, $master=null, $foreign_key=null, $parent_prefix = null)
+ {
+ if (!isset($master)) $master = $this->Tables;
+
+ // recalling by different name, because we may get kDBList, if we recall just by prefix
+ if (!preg_match('/(.*)-item$/', $special)) {
+ $special .= '-item';
+ }
+
+ $object =& $this->Application->recallObject($prefix.'.'.$special, $prefix, Array('skip_autoload' => true));
+
+ foreach ($ids as $id) {
+ $mode = 'create';
+ if ( $cloned_ids = getArrayValue($this->AlreadyProcessed, $master['TableName']) ) {
+ // if we have already cloned the id, replace it with cloned id and set mode to update
+ // update mode is needed to update second ForeignKey for items cloned by first ForeignKey
+ if ( getArrayValue($cloned_ids, $id) ) {
+ $id = $cloned_ids[$id];
+ $mode = 'update';
+ }
+ }
+
+ $object->Load($id);
+ $original_values = $object->FieldValues;
+
+ $object->NameCopy($master, $foreign_key);
+
+ if (isset($foreign_key)) {
+ $master_foreign_key_field = is_array($master['ForeignKey']) ? $master['ForeignKey'][$parent_prefix] : $master['ForeignKey'];
+ $object->SetDBField($master_foreign_key_field, $foreign_key);
+ }
+
+ if ($mode == 'create') {
+ $this->RaiseEvent('OnBeforeClone', $master['Prefix'], $special, Array($object->GetId()), $foreign_key);
+ }
+
+ $res = $mode == 'update' ? $object->Update() : $object->Create();
+
+ if ($res)
+ {
+ if ( $mode == 'create' && is_array( getArrayValue($master, 'ForeignKey')) ) {
+ // remember original => clone mapping for dual ForeignKey updating
+ $this->AlreadyProcessed[$master['TableName']][$id] = $object->GetId();
+ }
+ if($object->mode == 't') $object->setTempID();
+ if ($mode == 'create') {
+ $this->RaiseEvent('OnAfterClone', $master['Prefix'], $special, Array($object->GetId()), $foreign_key, array('original_id' => $id) );
+ $this->saveID($master['Prefix'], $special, $object->GetID());
+ }
+
+ if ( is_array(getArrayValue($master, 'SubTables')) ) {
+ foreach($master['SubTables'] as $sub_table) {
+ if (!getArrayValue($sub_table, 'AutoClone')) continue;
+ $sub_TableName = ($object->mode == 't') ? $this->GetTempName($sub_table['TableName']) : $sub_table['TableName'];
+
+ $foreign_key_field = is_array($sub_table['ForeignKey']) ? $sub_table['ForeignKey'][$master['Prefix']] : $sub_table['ForeignKey'];
+ $parent_key_field = is_array($sub_table['ParentTableKey']) ? $sub_table['ParentTableKey'][$master['Prefix']] : $sub_table['ParentTableKey'];
+
+ $query = 'SELECT '.$sub_table['IdField'].' FROM '.$sub_TableName.'
+ WHERE '.$foreign_key_field.' = '.$original_values[$parent_key_field];
+ if (isset($sub_table['Constrain'])) $query .= ' AND '.$sub_table['Constrain'];
+
+ $sub_ids = $this->Conn->GetCol($query);
+
+ if ( is_array(getArrayValue($sub_table, 'ForeignKey')) ) {
+ // $sub_ids could containt newly cloned items, we need to remove it here
+ // to escape double cloning
+
+ $cloned_ids = getArrayValue($this->AlreadyProcessed, $sub_table['TableName']);
+ if ( !$cloned_ids ) $cloned_ids = Array();
+ $new_ids = array_values($cloned_ids);
+ $sub_ids = array_diff($sub_ids, $new_ids);
+ }
+
+ $parent_key = $object->GetDBField($parent_key_field);
+
+ $this->CloneItems($sub_table['Prefix'], $special, $sub_ids, $sub_table, $parent_key, $master['Prefix']);
+ }
+ }
+ }
+ }
+
+ if (!$ids) {
+ $this->savedIDs[$prefix.($special ? '.' : '').$special] = Array();
+ }
+
+ return $this->savedIDs[$prefix.($special ? '.' : '').$special];
+ }
+
+ function DeleteItems($prefix, $special, $ids, $master=null, $foreign_key=null)
+ {
+ if (!isset($master)) $master = $this->Tables;
+ if( strpos($prefix,'.') !== false ) list($prefix,$special) = explode('.', $prefix, 2);
+
+ $prefix_special = rtrim($prefix.'.'.$special, '.');
+
+ //recalling by different name, because we may get kDBList, if we recall just by prefix
+ $recall_prefix = $prefix_special.($special ? '' : '.').'-item';
+ $object =& $this->Application->recallObject($recall_prefix, $prefix, Array('skip_autoload' => true));
+
+ foreach ($ids as $id)
+ {
+ $object->Load($id);
+ $original_values = $object->FieldValues;
+ if( !$object->Delete($id) ) continue;
+
+ if ( is_array(getArrayValue($master, 'SubTables')) ) {
+ foreach($master['SubTables'] as $sub_table) {
+ if (!getArrayValue($sub_table, 'AutoDelete')) continue;
+ $sub_TableName = ($object->mode == 't') ? $this->GetTempName($sub_table['TableName']) : $sub_table['TableName'];
+
+ $foreign_key_field = is_array($sub_table['ForeignKey']) ? getArrayValue($sub_table, 'ForeignKey', $master['Prefix']) : $sub_table['ForeignKey'];
+ $parent_key_field = is_array($sub_table['ParentTableKey']) ? getArrayValue($sub_table, 'ParentTableKey', $master['Prefix']) : $sub_table['ParentTableKey'];
+
+ if (!$foreign_key_field || !$parent_key_field) continue;
+
+ $query = 'SELECT '.$sub_table['IdField'].' FROM '.$sub_TableName.'
+ WHERE '.$foreign_key_field.' = '.$original_values[$parent_key_field];
+
+ $sub_ids = $this->Conn->GetCol($query);
+
+ $parent_key = $object->GetDBField(is_array($sub_table['ParentTableKey']) ? $sub_table['ParentTableKey'][$prefix] : $sub_table['ParentTableKey']);
+
+ $this->DeleteItems($sub_table['Prefix'], '', $sub_ids, $sub_table, $parent_key);
+ }
+ }
+
+ }
+ }
+
+ function DoCopyLiveToTemp($master, $ids, $parent_prefix=null)
+ {
+ // when two tables refers the same table as sub-sub-table, and ForeignKey and ParentTableKey are arrays
+ // the table will be first copied by first sub-table, then dropped and copied over by last ForeignKey in the array
+ // this should not do any problems :)
+ if ( !preg_match("/.*\.[0-9]+/", $master['Prefix']) ) {
+ if( $this->DropTempTable($master['TableName']) )
+ {
+ $this->CreateTempTable($master['TableName']);
+ }
+ }
+
+ if (is_array($ids)) {
+ $ids = join(',', $ids);
+ }
+
+ $table_sig = $master['TableName'].(isset($master['Constrain']) ? $master['Constrain'] : '');
+
+ if ($ids != '' && !in_array($table_sig, $this->CopiedTables)) {
+ if ( getArrayValue($master, 'ForeignKey') ) {
+ if ( is_array($master['ForeignKey']) ) {
+ $key_field = $master['ForeignKey'][$parent_prefix];
+ }
+ else {
+ $key_field = $master['ForeignKey'];
+ }
+ }
+ else {
+ $key_field = $master['IdField'];
+ }
+
+ $query = 'INSERT INTO '.$this->GetTempName($master['TableName']).'
+ SELECT * FROM '.$master['TableName'].'
+ WHERE '.$key_field.' IN ('.$ids.')';
+ if (isset($master['Constrain'])) $query .= ' AND '.$master['Constrain'];
+ $this->Conn->Query($query);
+
+ $this->CopiedTables[] = $table_sig;
+
+ $query = 'SELECT '.$master['IdField'].' FROM '.$master['TableName'].'
+ WHERE '.$key_field.' IN ('.$ids.')';
+ if (isset($master['Constrain'])) $query .= ' AND '.$master['Constrain'];
+ $this->RaiseEvent( 'OnAfterCopyToTemp', $master['Prefix'], '', $this->Conn->GetCol($query) );
+ }
+
+ if ( getArrayValue($master, 'SubTables') ) {
+ foreach ($master['SubTables'] as $sub_table) {
+
+ $parent_key = is_array($sub_table['ParentTableKey']) ? $sub_table['ParentTableKey'][$master['Prefix']] : $sub_table['ParentTableKey'];
+ if (!$parent_key) continue;
+
+ if ( $ids != '' && $parent_key != $key_field ) {
+ $query = 'SELECT '.$parent_key.' FROM '.$master['TableName'].'
+ WHERE '.$key_field.' IN ('.$ids.')';
+ $sub_foreign_keys = join(',', $this->Conn->GetCol($query));
+ }
+ else {
+ $sub_foreign_keys = $ids;
+ }
+ $this->DoCopyLiveToTemp($sub_table, $sub_foreign_keys, $master['Prefix']);
+ }
+ }
+ }
+
+ function GetForeignKeys($master, $sub_table, $live_id, $temp_id=null)
+ {
+ $mode = 1; //multi
+ if (!is_array($live_id)) {
+ $live_id = Array($live_id);
+ $mode = 2; //single
+ }
+ if (isset($temp_id) && !is_array($temp_id)) $temp_id = Array($temp_id);
+
+ if ( isset($sub_table['ParentTableKey']) ) {
+ if ( is_array($sub_table['ParentTableKey']) ) {
+ $parent_key_field = $sub_table['ParentTableKey'][$master['Prefix']];
+ }
+ else {
+ $parent_key_field = $sub_table['ParentTableKey'];
+ }
+ }
+ else {
+ $parent_key_field = $master['IdField'];
+ }
+
+ if ( $cached = getArrayValue($this->FKeysCache, $master['TableName'].'.'.$parent_key_field) ) {
+ if ( array_key_exists(serialize($live_id), $cached) ) {
+ list($live_foreign_key, $temp_foreign_key) = $cached[serialize($live_id)];
+ if ($mode == 1) {
+ return $live_foreign_key;
+ }
+ else {
+ return Array($live_foreign_key[0], $temp_foreign_key[0]);
+ }
+ }
+ }
+
+ if ($parent_key_field != $master['IdField']) {
+ $query = 'SELECT '.$parent_key_field.' FROM '.$master['TableName'].'
+ WHERE '.$master['IdField'].' IN ('.join(',', $live_id).')';
+ $live_foreign_key = $this->Conn->GetCol($query);
+
+ if (isset($temp_id)) {
+ $query = 'SELECT '.$parent_key_field.' FROM '.$this->GetTempName($master['TableName']).'
+ WHERE '.$master['IdField'].' IN ('.join(',', $temp_id).')';
+ $temp_foreign_key = $this->Conn->GetCol($query);
+ }
+ else {
+ $temp_foreign_key = Array();
+ }
+ }
+ else {
+ $live_foreign_key = $live_id;
+ $temp_foreign_key = $temp_id;
+ }
+
+ $this->FKeysCache[$master['TableName'].'.'.$parent_key_field][serialize($live_id)] = Array($live_foreign_key, $temp_foreign_key);
+
+ if ($mode == 1) {
+ return $live_foreign_key;
+ }
+ else {
+ return Array($live_foreign_key[0], $temp_foreign_key[0]);
+ }
+ }
+
+ function DoCopyTempToOriginal($master, $parent_prefix=null)
+ {
+ $query = 'SELECT '.$master['IdField'].' FROM '.$this->GetTempName($master['TableName']);
+ if (isset($master['Constrain'])) $query .= ' WHERE '.$master['Constrain'];
+ $current_ids = $this->Conn->GetCol($query);
+
+ $table_sig = $master['TableName'].(isset($master['Constrain']) ? $master['Constrain'] : '');
+
+ if ($current_ids) {
+ // delete all ids from live table - for MasterTable ONLY!
+ // because items from Sub Tables get deteleted in CopySubTablesToLive !BY ForeignKey!
+ if ($master['TableName'] == $this->MasterTable) {
+ $this->RaiseEvent( 'OnBeforeDeleteFromLive', $master['Prefix'], '', $current_ids );
+
+ $query = 'DELETE FROM '.$master['TableName'].' WHERE '.$master['IdField'].' IN ('.join(',', $current_ids).')';
+ $this->Conn->Query($query);
+ }
+
+ if ( getArrayValue($master, 'SubTables') ) {
+ if( in_array($table_sig, $this->CopiedTables) || $this->FinalRefs[$table_sig] != $master['TableId'] ) return;
+
+ foreach($current_ids AS $id)
+ {
+ $this->RaiseEvent( 'OnBeforeCopyToLive', $master['Prefix'], '', Array($id) );
+
+ //reset negative ids to 0, so autoincrement in live table works fine
+ if($id < 0)
+ {
+ $query = 'UPDATE '.$this->GetTempName($master['TableName']).'
+ SET '.$master['IdField'].' = 0
+ WHERE '.$master['IdField'].' = '.$id;
+ if (isset($master['Constrain'])) $query .= ' AND '.$master['Constrain'];
+ $this->Conn->Query($query);
+ $id_to_copy = 0;
+ }
+ else
+ {
+ $id_to_copy = $id;
+ }
+
+ //copy current id_to_copy (0 for new or real id) to live table
+ $query = 'INSERT INTO '.$master['TableName'].'
+ SELECT * FROM '.$this->GetTempName($master['TableName']).'
+ WHERE '.$master['IdField'].' = '.$id_to_copy;
+ $this->Conn->Query($query);
+ $insert_id = $id_to_copy == 0 ? $this->Conn->getInsertID() : $id_to_copy;
+
+ $this->RaiseEvent( 'OnAfterCopyToLive', $master['Prefix'], '', Array($insert_id), null, array('temp_id' => $id) );
+
+ $this->UpdateForeignKeys($master, $insert_id, $id);
+
+ //delete already copied record from master temp table
+ $query = 'DELETE FROM '.$this->GetTempName($master['TableName']).'
+ WHERE '.$master['IdField'].' = '.$id_to_copy;
+ if (isset($master['Constrain'])) $query .= ' AND '.$master['Constrain'];
+ $this->Conn->Query($query);
+ }
+
+ $this->CopiedTables[] = $table_sig;
+
+ // when all of ids in current master has been processed, copy all sub-tables data
+ $this->CopySubTablesToLive($master, $current_ids);
+ }
+ elseif( !in_array($table_sig, $this->CopiedTables) && ($this->FinalRefs[$table_sig] == $master['TableId']) ) { //If current master doesn't have sub-tables - we could use mass operations
+ // We don't need to delete items from live here, as it get deleted in the beggining of the method for MasterTable
+ // or in parent table processing for sub-tables
+ $this->RaiseEvent('OnBeforeCopyToLive', $master['Prefix'], '', $current_ids);
+
+ // reset ALL negative IDs to 0 so it get inserted into live table with autoincrement
+ $query = 'UPDATE '.$this->GetTempName($master['TableName']).'
+ SET '.$master['IdField'].' = 0
+ WHERE '.$master['IdField'].' < 0';
+ if (isset($master['Constrain'])) $query .= ' AND '.$master['Constrain'];
+ $this->Conn->Query($query);
+
+ // copy ALL records to live table
+ $query = 'INSERT INTO '.$master['TableName'].'
+ SELECT * FROM '.$this->GetTempName($master['TableName']);
+ if (isset($master['Constrain'])) $query .= ' WHERE '.$master['Constrain'];
+ $this->Conn->Query($query);
+
+ $this->CopiedTables[] = $table_sig;
+ /*
+
+ !!! WE NEED TO FIND A WAY TO DETERMINE IF OnAfterCopyToLive is not an empty method, and do on-by-one insert
+ and pass Ids to OnAfterCopyToLive, otherwise it's not smart to do on-by-one insert for any object
+ OR WE COULD FIND A WAY TO GET ALL INSERTED IDS as an array and iterate them !!!
+
+ $this->RaiseEvent('OnAfterCopyToLive', IDS ??? );
+
+ */
+
+ // no need to clear temp table - it will be dropped by next statement
+ }
+ }
+
+ if ($this->FinalRefs[ $master['TableName'] ] != $master['TableId']) return;
+
+ /*if ( is_array(getArrayValue($master, 'ForeignKey')) ) { //if multiple ForeignKeys
+ if ( $master['ForeignKey'][$parent_prefix] != end($master['ForeignKey']) ) {
+ return; // Do not delete temp table if not all ForeignKeys have been processed (current is not the last)
+ }
+ }*/
+ $this->DropTempTable($master['TableName']);
+ }
+
+ function UpdateForeignKeys($master, $live_id, $temp_id) {
+ foreach ($master['SubTables'] as $sub_table) {
+ $foreign_key_field = is_array($sub_table['ForeignKey']) ? getArrayValue($sub_table, 'ForeignKey', $master['Prefix']) : $sub_table['ForeignKey'];
+ if (!$foreign_key_field) return;
+
+ list ($live_foreign_key, $temp_foreign_key) = $this->GetForeignKeys($master, $sub_table, $live_id, $temp_id);
+
+ //Update ForeignKey in sub TEMP table
+ if ($live_foreign_key != $temp_foreign_key) {
+ $query = 'UPDATE '.$this->GetTempName($sub_table['TableName']).'
+ SET '.$foreign_key_field.' = '.$live_foreign_key.'
+ WHERE '.$foreign_key_field.' = '.$temp_foreign_key;
+ if (isset($sub_table['Constrain'])) $query .= ' AND '.$sub_table['Constrain'];
+ $this->Conn->Query($query);
+ }
+ }
+ }
+
+ function CopySubTablesToLive($master, $current_ids) {
+ foreach ($master['SubTables'] as $sub_table) {
+
+ $table_sig = $sub_table['TableName'].(isset($sub_table['Constrain']) ? $sub_table['Constrain'] : '');
+
+ // delete records from live table by foreign key, so that records deleted from temp table
+ // get deleted from live
+ if (count($current_ids) > 0 && !in_array($table_sig, $this->CopiedTables) ) {
+ $foreign_key_field = is_array($sub_table['ForeignKey']) ? getArrayValue($sub_table, 'ForeignKey', $master['Prefix']) : $sub_table['ForeignKey'];
+ if (!$foreign_key_field) continue;
+ $foreign_keys = $this->GetForeignKeys($master, $sub_table, $current_ids);
+ // Do not delete live sub-items with 0 id
+ // otherwise home category permissions got deleted when creating new category
+ $zero_id = array_search(0, $foreign_keys);
+ if ($zero_id !== false) {
+ array_splice($foreign_keys, $zero_id, 1);
+ }
+ if (count($foreign_keys) > 0) {
+ $query = 'SELECT '.$sub_table['IdField'].' FROM '.$sub_table['TableName'].'
+ WHERE '.$foreign_key_field.' IN ('.join(',', $foreign_keys).')';
+ if (isset($sub_table['Constrain'])) $query .= ' AND '.$sub_table['Constrain'];
+
+ $this->RaiseEvent( 'OnBeforeDeleteFromLive', $sub_table['Prefix'], '', $this->Conn->GetCol($query) );
+
+ $query = 'DELETE FROM '.$sub_table['TableName'].'
+ WHERE '.$foreign_key_field.' IN ('.join(',', $foreign_keys).')';
+ if (isset($sub_table['Constrain'])) $query .= ' AND '.$sub_table['Constrain'];
+ $this->Conn->Query($query);
+ }
+ }
+ //sub_table passed here becomes master in the method, and recursively updated and copy its sub tables
+ $this->DoCopyTempToOriginal($sub_table, $master['Prefix']);
+ }
+ }
+
+ function RaiseEvent($name, $prefix, $special, $ids, $foreign_key = null, $add_params = null)
+ {
+ if ( !is_array($ids) ) return ;
+
+ $event_key = $prefix.($special ? '.' : '').$special.':'.$name;
+ $event = new kEvent($event_key);
+ if (isset($foreign_key)) {
+ $event->setEventParam('foreign_key', $foreign_key);
+ }
+
+ foreach($ids as $id)
+ {
+ $event->setEventParam('id', $id);
+ if (is_array($add_params)) {
+ foreach ($add_params as $name => $val) {
+ $event->setEventParam($name, $val);
+ }
+ }
+ $this->Application->HandleEvent($event);
+ }
+ }
+
+ function DropTempTable($table)
+ {
+ if( in_array($table, $this->DroppedTables) ) return false;
+ $query = sprintf("DROP TABLE IF EXISTS %s",
+ $this->GetTempName($table)
+ );
+ array_push($this->DroppedTables, $table);
+ $this->DroppedTables = array_unique($this->DroppedTables);
+ $this->Conn->Query($query);
+ return true;
+ }
+
+ function PrepareEdit()
+ {
+ $this->DoCopyLiveToTemp($this->Tables, $this->Tables['IDs']);
+ }
+
+ function SaveEdit($skip_master=0)
+ {
+ $this->DoCopyTempToOriginal($this->Tables);
+ }
+
+ function CancelEdit($master=null)
+ {
+ if (!isset($master)) $master = $this->Tables;
+ $this->DropTempTable($master['TableName']);
+ if ( getArrayValue($master, 'SubTables') ) {
+ foreach ($master['SubTables'] as $sub_table) {
+ $this->CancelEdit($sub_table);
+ }
+ }
+ }
+}
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.25.2/core/kernel/utility/temp_handler.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.25
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property

Event Timeline