public function action() { // Objects $xml = $this->getXML(); $xml->addFullTag("view_log",$this->_generic->getFullPath("SLS_Bo","LogsMonitoring",array(),false)); $user = $this->hasAuthorative(); $xml = $this->makeMenu($xml); // Get the existing logs $dates = array(); $all = array(); $handle = opendir($this->_generic->getPathConfig("logs")."monitoring"); // Foreach directories while (false !== ($dir = readdir($handle))) { if (is_dir($this->_generic->getPathConfig("logs")."/monitoring/".$dir) && substr($dir, 0, 1) != ".") { $handle2 = opendir($this->_generic->getPathConfig("logs")."/monitoring/".$dir); while (false !== ($file = readdir($handle2))) { if (!is_dir($this->_generic->getPathConfig("logs")."/monitoring/".$dir."/".$file) && substr($file, 0, 1) != ".") { $date = explode("-",substr($file,0,10)); if (!in_array(substr($file,0,10),$dates)) { $array = array("year"=>$date[0],"month"=>$date[1],"day"=>$date[2]); array_push($all,$array); array_push($dates,substr($file,0,10)); } } } } } if (!empty($all)) { $all = SLS_String::arrayMultiSort($all,array(array('key'=>'year','sort'=>'desc'),array('key'=>'month','sort'=>'desc'),array('key'=>'day','sort'=>'desc'))); $xml->startTag("logs"); foreach($all as $allC) { $dateL = new SLS_Date($allC["year"]."-".$allC["month"]."-".$allC["day"]); $xml->startTag("log"); $xml->addFullTag("year",$allC["year"],true); $xml->addFullTag("month",$allC["month"],true); $xml->addFullTag("day",$allC["day"],true); $xml->addFullTag("litteral",ucwords($dateL->getDate("FULL_LITTERAL"))); $xml->endTag("log"); } $xml->endTag("logs"); } $this->saveXML($xml); }
public function action() { // Objects $xml = $this->getXML(); $user = $this->hasAuthorative(); $xml = $this->makeMenu($xml); $date = $this->_http->getParam("date"); $dateE = explode("-",$date); $dateL = new SLS_Date($date); if (is_array($dateE) && count($dateE) == 3 && is_dir($this->_generic->getPathConfig("logs").$dateE[0]."-".$dateE[1])) { $content = ""; $i = 0; while(file_exists($this->_generic->getPathConfig("logs").$dateE[0]."-".$dateE[1]."/".$dateE[0]."-".$dateE[1]."-".$dateE[2]."_".$i.".log")) { $content .= file_get_contents($this->_generic->getPathConfig("logs").$dateE[0]."-".$dateE[1]."/".$dateE[0]."-".$dateE[1]."-".$dateE[2]."_".$i.".log"); $i++; } $errors = explode($date,$content); $xml->startTag("errors"); $xml->addFullTag("date",$dateL->getDate("FULL_LITTERAL")); foreach($errors as $error) { if (!empty($error)) { $stack = explode("\n",$error); $xml->startTag("error"); $xml->addFullTag("title",$date.$stack[0]); $xml->startTag("traces"); for($j=1 ; $j<$count=count($stack) ; $j++) { if (!empty($stack[$j])) { $trace = explode("in file",$stack[$j]); $xml->startTag("trace"); $xml->addFullTag("message",$trace[0],true); $xml->addFullTag("file","in file".$trace[1],true); $xml->endTag("trace"); } } $xml->endTag("traces"); $xml->endTag("error"); } } $xml->endTag("errors"); } $this->saveXML($xml); }
/** * Check if an admin is authorized to log in * * @access public static * @param string $login login * @param string $pwd password * @return mixed 1 if connected, 0 if expired, -1 not logged, -2 disabled * @since 1.0 */ public static function connect($login,$pwd) { $generic = SLS_Generic::getInstance(); $session = $generic->getObjectSession(); $sessionToken = substr(substr(sha1($generic->getSiteConfig("privateKey")),12,31).substr(sha1($generic->getSiteConfig("privateKey")),4,11),6); $pathsHandle = file_get_contents($generic->getPathConfig("configSls")."/rights.xml"); $xmlRights = new SLS_XMLToolbox($pathsHandle); $result = array_shift($xmlRights->getTagsAttributes("//sls_configs/entry[@login='******' and @password='******' and count(action) > 0]",array("login"))); if (!empty($result)) { $attributes = array_shift($xmlRights->getTagsAttributes("//sls_configs/entry[@login='******' and @password='******']",array("reset_pwd","renew_pwd","last_renew_pwd","name","firstname","last_connection","enabled"))); $reset_pwd = $attributes["attributes"][0]["value"]; $renew_pwd = $attributes["attributes"][1]["value"]; $last_renew_pwd = $attributes["attributes"][2]["value"]; $name = $attributes["attributes"][3]["value"]; $firstname = $attributes["attributes"][4]["value"]; $lastLogin = $attributes["attributes"][5]["value"]; $enabled = $attributes["attributes"][6]["value"]; if ($reset_pwd == "true" || (!empty($last_renew_pwd) && !empty($renew_pwd) && (strtotime("+".$renew_pwd, SLS_Date::dateToTimestamp($last_renew_pwd)) < SLS_Date::dateToTimestamp(date("Y-m-d"))))) return 0; if ($enabled == "false") return -2; $xmlRights->setTagAttributes("//sls_configs/entry[@login='******']",array("last_connection" => date("Y-m-d H:i:s"))); $xmlRights->saveXML($generic->getPathConfig("configSls")."/rights.xml",$xmlRights->getXML()); $session->setParam("SLS_BO_VALID_".$sessionToken,"true"); $session->setParam("SLS_BO_USER_".$sessionToken,$login); $session->setParam("SLS_BO_PREVIOUS_LOGIN",$lastLogin); $session->setParam("SLS_BO_LOGGED","true"); $session->setParam("SLS_BO_USER",$login); $session->setParam("SLS_BO_USER_NAME",$name); $session->setParam("SLS_BO_USER_FIRSTNAME",$firstname); $session->setParam("ckfinderAuthorized",true); return 1; } else return -1; }
public function action() { // Objects $xml = $this->getXML(); $user = $this->hasAuthorative(); $xml = $this->makeMenu($xml); $date = $this->_http->getParam("date"); $dateE = explode("-",$date); $dateL = new SLS_Date($date); if (is_array($dateE) && count($dateE) == 3 && is_dir($this->_generic->getPathConfig("logs")."monitoring/".$dateE[0]."-".$dateE[1])) { $content = ""; $i = 0; while(file_exists($this->_generic->getPathConfig("logs")."monitoring/".$dateE[0]."-".$dateE[1]."/".$dateE[0]."-".$dateE[1]."-".$dateE[2]."_".$i.".log")) { $content .= file_get_contents($this->_generic->getPathConfig("logs")."monitoring/".$dateE[0]."-".$dateE[1]."/".$dateE[0]."-".$dateE[1]."-".$dateE[2]."_".$i.".log"); $i++; } $batchs = explode("#|end|#",$content); $xml->startTag("batchs"); $xml->addFullTag("date",$dateL->getDate("FULL_LITTERAL")); foreach($batchs as $batch) { if (!empty($batch)) { $lines = explode("\n",$batch); $times = array ("Render" => 0, "XML/XSL Parsing" => 0, "MySQL Query" => 0, "Controller Action" => 0, "Controller Front" => 0, "Controller Static" => 0); $msg = ""; $totalTime = 0; $endTime = 0; $xml->startTag("batch"); $xml->startTag("lines"); foreach($lines as $line) { $infos = explode("||",$line); $infos = array_map('trim',$infos); if (count($infos) > 4) { $times[$infos[0]] += $infos[2]; if ($infos[0] == "Render") { $totalTime = $infos[2]; $endTime = SLS_String::substrAfterFirstDelimiter($infos[1]," "); } if ($infos[0] == "Controller Front") $msg = SLS_String::substrAfterFirstDelimiter(SLS_String::substrBeforeLastDelimiter($infos[3],")"),"("); $xml->startTag("line"); $xml->addFullTag("msg",$infos[3],true); $xml->addFullTag("type",$infos[0],true); $xml->addFullTag("more",str_replace(array("|n|","|t|"," "),array("<br />","  ","    "),$infos[4]),true); $xml->addFullTag("time",SLS_String::substrAfterFirstDelimiter($infos[1]," "),true); $xml->addFullTag("duration",$infos[2],true); $xml->endTag("line"); } } $xml->endTag("lines"); $xml->startTag("infos"); $xml->addFullTag("name",$endTime." - ".$msg,true); $xml->startTag("times"); $xml->addFullTag("total",$totalTime,true); foreach($times as $key => $value) $xml->addFullTag(SLS_String::stringToUrl(trim($key),"_"),$value,true); $xml->endTag("times"); $xml->endTag("infos"); $sum = 0; $xml->startTag("ratios"); foreach($times as $key => $value) { if ($key == "Render") continue; else $sum += $value; $xml->startTag("ratio"); $xml->addFullTag("label",str_replace(" ","+",trim($key)),true); $xml->addFullTag("duration",$times[$key],true); $xml->addFullTag("degree",($totalTime > 0) ? 360 * $value / $totalTime : "360",true); $xml->endTag("ratio"); } if ($totalTime - $sum > 0) { $xml->startTag("ratio"); $xml->addFullTag("label","Others",true); $xml->addFullTag("duration",$sum,true); $xml->addFullTag("degree",($totalTime > 0) ? 360 * $sum / $totalTime : "360",true); $xml->endTag("ratio"); } $xml->endTag("ratios"); $xml->endTag("batch"); } } $xml->endTag("batchs"); } $this->saveXML($xml); }
/** * Constructor * * @access public * @since 1.0 */ public function __construct($xml,$db,$table,$forward=true) { parent::__construct(); $this->_xml = $xml; $this->_db_alias = $db; $this->_table = $table; $this->_forward = $forward; # Objects $className = ucfirst(strtolower($this->_db_alias))."_".SLS_String::tableToClass($this->_table); $this->_generic->useModel(SLS_String::tableToClass($this->_table),ucfirst(strtolower($this->_db_alias)),"user"); $this->_object = new $className(); $this->_table = $this->_object->getTable(); $this->_clone = new $className(); $this->_columns = array(); $this->_filters = array(); $this->_types = array(); # /Objects # Params $ids = $this->_http->getParam("id"); $ids = (SLS_String::contains($ids,"|")) ? explode("|",$ids) : array($ids); # /Params # Types $types = $this->_db->showColumns($this->_table); for($i=0 ; $i<$count=count($types) ; $i++) { $nativeType = "text"; switch($types[$i]->Type) { case (false !== $typeMatch = $this->containsRecursive($types[$i]->Type,array("int","float","double","decimal","real"))): $nativeType = "number"; break; case (false !== $typeMatch = $this->containsRecursive($types[$i]->Type,array("year","datetime","timestamp","time","date"))): $nativeType = "date_".$typeMatch; break; } $this->_types[$types[$i]->Field] = $nativeType; } # /Types # Blocking specificities $specificities = $this->_xmlType->getTagsAttributes("//sls_configs/entry[@table='".$this->_db_alias."_".$this->_table."' and (@type='position' or @type='uniqid' or @type='email')]",array("column","type")); for($i=0 ; $i<$count=count($specificities) ; $i++) { $column = $specificities[$i]["attributes"][0]["value"]; $type = $specificities[$i]["attributes"][1]["value"]; if (!array_key_exists($column,$this->_columns)) $this->_columns[$column] = $type; } $filters = $this->_xmlFilter->getTags("//sls_configs/entry[@table='".$this->_db_alias."_".$this->_table."' and @filter='hash']/@column"); # Blocking specificities # Perform clone if ($this->_object->isMultilanguage()) { $siteLangs = $this->_lang->getSiteLangs(); unset($siteLangs[array_search($this->_defaultLang,$siteLangs)]); array_unshift($siteLangs,$this->_defaultLang); $langs = $siteLangs; } else $langs = array($this->_defaultLang); // Recordsets to clone $nbClone = 0; foreach($ids as $id) { // Next id $cloneId = $this->_object->giveNextId(); // Each lang foreach($langs as $lang) { if ($this->_object->isMultilanguage()) $this->_clone->setModelLanguage($lang); // Get recordset if ($this->_object->getModel($id) === true) { // Foreach column foreach($this->_object->getParams() as $key => $value) { if ($key == $this->_object->getPrimaryKey() || $key == "pk_lang") continue; // Setter $functionName = "set".SLS_String::fullTrim(ucwords(SLS_String::stringToUrl(str_replace("_"," ",$key)," ",false)),""); // Specific type ? if (array_key_exists($key,$this->_columns) && $this->_columns[$key] != "email") { // Default lang if ($lang == $this->_defaultLang && in_array($this->_columns[$key],array("uniqid","position"))) { // Regenerate uniqid if ($this->_columns[$key] == "uniqid") $value = substr(md5(time().substr(sha1(microtime()),0,rand(12,25))),mt_rand(1,20),40); // Get next position else if ($this->_columns[$key] == "position") { $record = array_shift($this->_db->select("SELECT MAX(`".$key."`) AS max_position FROM `".$this->_table."` ")); $value = (!empty($record->max_position) && is_numeric($record->max_position) && $record->max_position > 0) ? ($record->max_position+1) : 1; } } // Take the default lang value else $value = $this->_clone->__get($key); } // Set if (in_array($key,$filters)) $this->_clone->__set($key,$value); else $this->_clone->$functionName($value); // Unique error ? if ($this->_clone->getError($key) == "E_UNIQUE") { if (array_key_exists($key,$this->_columns) && $this->_columns[$key] == "email") $value = "clone_".time()."@".((substr_count($this->_generic->getSiteConfig("domainName"),".") > 1) ? SLS_String::substrAfterLastDelimiter(SLS_String::substrBeforeLastDelimiter($this->_generic->getSiteConfig("domainName"),"."),".").".".SLS_String::substrAfterLastDelimiter($this->_generic->getSiteConfig("domainName"),".") : $this->_generic->getSiteConfig("domainName")); else { switch($this->_types[$key]) { case "number": $record = array_shift($this->_db->select("SELECT MAX(`".$key."`) AS max_nb FROM `".$this->_table."` ")); $value = (!empty($record->max_nb) && is_numeric($record->max_nb)) ? ($record->max_nb+1) : 1; break; case (SLS_String::startsWith($this->_types[$key],"date_")): $record = array_shift($this->_db->select("SELECT MAX(`".$key."`) AS max_date FROM `".$this->_table."` ")); $value = (!empty($record->max_date)) ? ($record->max_date) : ""; $dateType = SLS_String::substrAfterFirstDelimiter($this->_types[$key],"date_"); switch($dateType) { case (in_array($dateType,array("year","timestamp"))): $value = $value + 1; break; case "date": $value = SLS_Date::timestampToDate(strtotime("+ 1 second",SLS_Date::dateToTimestamp($value))); break; case "datetime": $value = SLS_Date::timestampToDateTime(strtotime("+ 1 second",SLS_Date::dateTimeToTimestamp($value))); break; case "time": $value = sls_string::substrAfterFirstDelimiter(SLS_Date::timestampToDateTime(strtotime("+ 1 second",SLS_Date::dateTimeToTimestamp(date("Y-m-d")." ".$value)))," "); break; } break; default: $value = substr(md5(time().substr(sha1(microtime()),0,rand(12,5))),mt_rand(1,5),10); break; } } $this->_clone->$functionName($value); } } $errors = $this->_clone->getErrors(); if (empty($errors)) { $this->_clone->create($cloneId); $nbClone += 1; } } } $this->_clone->clear(); } if ($this->_object->isMultilanguage() && is_numeric($nbClone) && $nbClone > 0) $nbClone = floor($nbClone / count($langs)); # Perform clone # Notif if (!empty($nbClone) && $nbClone !== false && is_numeric($nbClone)) $this->pushNotif("success",($nbClone==1) ? $GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_BO_GENERIC_SUBMIT_SUCCESS_CLONE'] : sprintf($GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_BO_GENERIC_SUBMIT_SUCCESS_CLONES'],$nbClone)); else $this->pushNotif("error",$GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_BO_GENERIC_SUBMIT_ERROR_CLONE']); # /Notif if ($this->_async) { if ($nbClone !== false && is_numeric($nbClone) && $nbClone > 0) { $this->_render["status"] = "OK"; $this->_render["result"]["message"] = ($nbClone==1) ? $GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_BO_GENERIC_SUBMIT_SUCCESS_CLONE'] : sprintf($GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_BO_GENERIC_SUBMIT_SUCCESS_CLONES'],$nbClone); $rememberList = (is_array($this->_session->getParam("SLS_BO_LIST"))) ? $this->_session->getParam("SLS_BO_LIST") : array(); if (array_key_exists($this->_db_alias."_".$this->_table,$rememberList) && !empty($rememberList[$this->_db_alias."_".$this->_table])) $this->_render["forward"] = $this->_generic->getSiteConfig("protocol")."://".$this->_generic->getSiteConfig("domainName")."/".$rememberList[$this->_db_alias."_".$this->_table]; else $this->_render["forward"] = $this->_generic->getFullPath($this->_boController,"List".ucfirst(strtolower($this->_db_alias))."_".SLS_String::tableToClass($this->_table)); } else $this->_render["result"]["message"] = $GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_BO_ASYNC_ERROR']; echo json_encode($this->_render); die(); } else { # Forward if ($this->_forward) { $rememberList = (is_array($this->_session->getParam("SLS_BO_LIST"))) ? $this->_session->getParam("SLS_BO_LIST") : array(); if (array_key_exists($this->_db_alias."_".$this->_table,$rememberList) && !empty($rememberList[$this->_db_alias."_".$this->_table])) $this->_generic->redirect($rememberList[$this->_db_alias."_".$this->_table]); else $this->_generic->forward($this->_boController,"List".ucfirst(strtolower($this->_db_alias))."_".SLS_String::tableToClass($this->_table)); } # /Forward } }
public function getSlsGraphXml(&$xml, $slsGraph) { $xml->startTag('sls_graph'); if(empty($slsGraph)) { $xml->endTag('sls_graph'); return; } $colors = array( '#ff275f', '#980067', '#0094a5', '#96be12', '#ffba00', '#ed7807', '#ba3ecc', '#07b3da', '#408cd0', '#004e8e', '#f06eaa', '#a764a7', '#81c99b', '#abd273', '#faae5d', '#f16c4f', '#f4979c', '#bc8bbe', '#8292c9', '#67c4e8' ); $labels = array('SLS_GRAPH_TYPE_PIE' => "Pie Chart", 'SLS_GRAPH_TYPE_BAR' => "Bar Chart", 'SLS_GRAPH_TYPE_PIVOT' => "Pivot Table", 'SLS_GRAPH_TYPE_LIST' => "List", 'SLS_AGGREGATION_TYPE_SUM' => "SUM", 'SLS_AGGREGATION_TYPE_AVG' => "AVG", 'SLS_AGGREGATION_TYPE_COUNT' => "COUNT", 'SLS_AGGREGATION_TYPE_SUM_LABEL' => "Sum", 'SLS_AGGREGATION_TYPE_AVG_LABEL' => "Average", 'SLS_AGGREGATION_TYPE_COUNT_LABEL' => "Total", 'SLS_QUERY_OPERATOR_LIKE' => "LIKE", 'SLS_QUERY_OPERATOR_NOTLIKE' => "NOT LIKE", 'SLS_QUERY_OPERATOR_STARTWITH' => "START WITH", 'SLS_QUERY_OPERATOR_ENDWITH' => "END WITH", 'SLS_QUERY_OPERATOR_EQUAL' => "EQUAL", 'SLS_QUERY_OPERATOR_NOTEQUAL' => "NOT EQUAL", 'SLS_QUERY_OPERATOR_IN' => "IN", 'SLS_QUERY_OPERATOR_NOTIN' => "NOT IN", 'SLS_QUERY_OPERATOR_LT' => "LESS THAN", 'SLS_QUERY_OPERATOR_LTE' => "LESS THAN EQUAL", 'SLS_QUERY_OPERATOR_GT' => "GREATER THAN", 'SLS_QUERY_OPERATOR_GTE' => "GREATER THAN EQUAL", 'SLS_QUERY_OPERATOR_NULL' => "IS NULL", 'SLS_QUERY_OPERATOR_NOTNULL' => "IS NOT NULL"); foreach ($slsGraph->getParams() as $key => $value) { if($key =='sls_graph_date_add') { if($value != '0000-00-00 00:00:00') { $date = new SLS_Date($value); $value = $date->getDate('DATE'); } else $value = '-'; } else if($key == 'sls_graph_type') $xml->addFullTag($key.'_label', $labels['SLS_GRAPH_TYPE_'.mb_strtoupper($value, 'UTF-8')], true); $xml->addFullTag($key, $value, true); } $this->_generic->useModel("Sls_graph_query",$this->defaultDb,"sls"); $className = ucfirst($this->defaultDb)."_Sls_graph_query"; $slsGraphQuery = new $className(); $slsGraphQuery->getModel($slsGraph->__get("sls_graph_query_id")); $request = $this->getSlsGraphQueryRequest($slsGraphQuery->sls_graph_query_id); $requestRender = str_replace(array("\t"),array(str_repeat(" ",4)),$request); $xml->addFullTag('sls_graph_query', $requestRender, true); $this->sql->changeDb($slsGraphQuery->__get("sls_graph_query_db_alias")); $results = $this->sql->select($request); if($results === false) { $xml->addFullTag('sls_graph_error', 'Invalid SQL query',true); } else { if($slsGraph->sls_graph_type == 'pie') { $xml->startTag('sls_graph_data'); $this->_generic->useModel("Sls_graph_query_group",$this->defaultDb,"sls"); $className = ucfirst($this->defaultDb)."_Sls_graph_query_group"; $slsGraphQueryGroup = new $className(); $groups = $slsGraphQueryGroup->searchModels("sls_graph_query_group",array(),array(0=>array("column"=>"sls_graph_query_id","value"=>$slsGraphQuery->sls_graph_query_id,"mode"=>"equal")),array(),array(array("column"=>"sls_graph_query_group_id","order"=>"asc"))); $columnGroupName = $groups[0]->sls_graph_query_group_column; foreach($results as $result) { $xml->startTag('sls_graph_data_line'); $xml->addFullTag('sls_graph_data_legend', (!empty($result->legend)) ? $result->legend : "Unknown", true); $xml->addFullTag('sls_graph_data_count', $result->count, true); $xml->endTag('sls_graph_data_line'); } $xml->endTag('sls_graph_data'); } else if($slsGraph->sls_graph_type == 'bar') { $this->_generic->useModel("Sls_graph_query_group",$this->defaultDb,"sls"); $className = ucfirst($this->defaultDb)."_Sls_graph_query_group"; $slsGraphQueryGroup = new $className(); $this->_generic->useModel("Sls_graph_query_column",$this->defaultDb,"sls"); $className = ucfirst($this->defaultDb)."_Sls_graph_query_column"; $slsGraphQueryColumn = new $className(); $xml->startTag('sls_graph_data'); $groups = $slsGraphQueryGroup->searchModels("sls_graph_query_group",array(),array(0=>array("column"=>"sls_graph_query_id","value"=>$slsGraphQuery->sls_graph_query_id,"mode"=>"equal")),array(),array(array("column"=>"sls_graph_query_group_id","order"=>"asc"))); $columnAggregation = array_shift($slsGraphQueryColumn->searchModels("sls_graph_query_column",array(),array(0=>array("column"=>"sls_graph_query_id","value"=>$slsGraphQuery->sls_graph_query_id,"mode"=>"equal")),array(),array(array("column"=>"sls_graph_query_column_id","order"=>"asc")))); $columnAggregationFunction = $columnAggregation->sls_graph_query_column_aggregation; $columnAggregationName = $columnAggregation->sls_graph_query_column_name; $columnGroupName = $groups[0]->sls_graph_query_group_column; if(count($groups) > 1) $columnStackedName = $groups[1]->sls_graph_query_group_column; else $columnStackedName = ''; if ($slsGraphQuery->sls_graph_query_db_alias != $this->sql->getCurrentDb()) $this->sql->changeDb($slsGraphQuery->sls_graph_query_db_alias); $columnsComment = $this->sql->showColumns($slsGraphQuery->sls_graph_query_table); $tablesComment = $this->sql->showTables(); $columnGroupComment = $this->array_pdo_search($columnsComment, 'Field', $columnGroupName)->Comment; $columnAggregationComment = $this->array_pdo_search($columnsComment, 'Field', $columnAggregationName)->Comment; if(!empty($columnStackedName)) $columnStackedComment = $this->array_pdo_search($columnsComment, 'Field', $columnStackedName)->Comment; else $columnStackedComment = ''; $tableComment = $this->array_pdo_search($tablesComment, 'Name', $slsGraphQuery->sls_graph_query_table)->Comment; $xml->addFullTag('sls_graph_data_aggregation_function', $columnAggregationFunction, true); $xml->addFullTag('sls_graph_data_legend_y', ($columnAggregationFunction == 'count' ? $tableComment : ($columnAggregationComment).' - '.$labels['SLS_AGGREGATION_TYPE_'.strtoupper($columnAggregationFunction).'_LABEL']), true); $xml->addFullTag('sls_graph_data_legend_x', $columnGroupComment, true); $xml->addFullTag('sls_graph_data_legend_stacked', $columnStackedComment, true); $xml->addFullTag('sls_graph_data_stacked', empty($columnStackedName) ? 'false' : 'true', true); $resultsGroup = array(); $resultsGroupId = array(); foreach($results as $result) { if(!in_array($result->legend_group_id, $resultsGroupId)) { array_push($resultsGroup, $result); array_push($resultsGroupId, $result->legend_group_id); } } foreach($resultsGroup as $resultGroup) { $xml->startTag('sls_graph_data_line'); $xml->addFullTag('sls_graph_data_legend', (!empty($resultGroup->legend_group)) ? $resultGroup->legend_group : "Unknown",true); $xml->addFullTag('sls_graph_data_value', round($resultGroup->value, 2),true); if(!empty($columnStackedName)) { $xml->startTag('sls_graph_sub_data'); foreach($results as $result) { if($result->legend_group == $resultGroup->legend_group) { $xml->startTag('sls_graph_sub_data_line'); $xml->addFullTag('sls_graph_sub_data_legend', $result->legend_stacked, true); $xml->addFullTag('sls_graph_sub_data_value', round($result->value, 2), true); $xml->endTag('sls_graph_sub_data_line'); } } $xml->endTag('sls_graph_sub_data'); } $xml->endTag('sls_graph_data_line'); } $xml->endTag('sls_graph_data'); } else if($slsGraph->sls_graph_type == 'pivot') { $this->_generic->useModel("Sls_graph_query_group",$this->defaultDb,"sls"); $className = ucfirst($this->defaultDb)."_Sls_graph_query_group"; $slsGraphQueryGroup = new $className(); $this->_generic->useModel("Sls_graph_query_column",$this->defaultDb,"sls"); $className = ucfirst($this->defaultDb)."_Sls_graph_query_column"; $slsGraphQueryColumn = new $className(); $xml->startTag('sls_graph_data'); $groups = $slsGraphQueryGroup->searchModels("sls_graph_query_group",array(),array(0=>array("column"=>"sls_graph_query_id","value"=>$slsGraphQuery->sls_graph_query_id,"mode"=>"equal")),array(),array(array("column"=>"sls_graph_query_group_id","order"=>"asc"))); $columnAggregation = array_shift($slsGraphQueryColumn->searchModels("sls_graph_query_column",array(),array(0=>array("column"=>"sls_graph_query_id","value"=>$slsGraphQuery->sls_graph_query_id,"mode"=>"equal")),array(),array(array("column"=>"sls_graph_query_column_id","order"=>"asc")))); $columnAggregationFunction = $columnAggregation->sls_graph_query_column_aggregation; $columnAggregationName = $columnAggregation->sls_graph_query_column_name; $columnLineName = $groups[0]->sls_graph_query_group_column; $columnColumndName = $groups[1]->sls_graph_query_group_column; if ($slsGraphQuery->sls_graph_query_db_alias != $this->sql->getCurrentDb()) $this->sql->changeDb($slsGraphQuery->sls_graph_query_db_alias); $columnsComment = $this->sql->showColumns($slsGraphQuery->sls_graph_query_table); $tablesComment = $this->sql->showTables(); $columnGroupComment = $this->array_pdo_search($columnsComment, 'Field', $columnLineName)->Comment; $columnAggregationComment = $this->array_pdo_search($columnsComment, 'Field', $columnAggregationName)->Comment; $columnStackedComment = $this->array_pdo_search($columnsComment, 'Field', $columnColumndName)->Comment; $tableComment = $this->array_pdo_search($tablesComment, 'Name', $slsGraphQuery->sls_graph_query_table)->Comment; $resultsLines = array(); $resultsLinesId = array(); foreach($results as $result) { if(!in_array($result->legend_line_id, $resultsLinesId)) { array_push($resultsLinesId, $result->legend_line_id); array_push($resultsLines, $result); } } $resultsColumns = array(); $resultsColumnsId = array(); foreach($results as $result) { if(!in_array($result->legend_column_id, $resultsColumnsId)) { array_push($resultsColumnsId, $result->legend_column_id); array_push($resultsColumns, $result); } } foreach($resultsLines as $resultsLine) { $xml->startTag('sls_graph_data_line'); $xml->addFullTag('sls_graph_data_legend',(empty($resultsLine->legend_line)) ? 'Unknown' : $resultsLine->legend_line, true); $xml->startTag('sls_graph_sub_data'); foreach($resultsColumns as $resultsColumn) { $xml->startTag('sls_graph_sub_data_line'); $result = $this->array_pdo_multiple_search($results, array('legend_line_id' => $resultsLine->legend_line_id, 'legend_column_id' => $resultsColumn->legend_column_id)); $value = !empty($result) ? $result->value : 0; $xml->addFullTag('sls_graph_sub_data_legend', empty($resultsColumn->legend_column) ? 'Unknown' : $resultsColumn->legend_column, true); $xml->addFullTag('sls_graph_sub_data_value', round($value, 2), true); $xml->endTag('sls_graph_sub_data_line'); } $xml->endTag('sls_graph_sub_data'); $xml->endTag('sls_graph_data_line'); } $xml->endTag('sls_graph_data'); } else if($slsGraph->sls_graph_type == 'list') { $xml->startTag('sls_graph_data'); foreach($results as $result) { $xml->startTag('sls_graph_data_line'); $xml->startTag('sls_graph_sub_data'); foreach($result as $key => $value) { $xml->startTag('sls_graph_sub_data_line'); $xml->addFullTag('sls_graph_sub_data_legend', $key, true); $xml->addFullTag('sls_graph_sub_data_value', $value, true); $xml->endTag('sls_graph_sub_data_line'); } $xml->endTag('sls_graph_sub_data'); $xml->endTag('sls_graph_data_line'); } $xml->endTag('sls_graph_data'); } } $xml->startTag('sls_graph_colors'); foreach($colors as $color) $xml->addFulLTag('sls_graph_color', $color, true); $xml->endTag('sls_graph_colors'); $xml->endTag('sls_graph'); }
/** * Get date part * * @access public * @param string $mode the date pattern ('TIME','FULL_TIME','DATE','MONTH_LITTERAL','FULL_LITTERAL','FULL_LITTERAL_TIME','MONTH_LITTERAL_TIME') or direct php date() pattern (use false in 2nd parameter) * @param bool $predefined true if you fill a predefined constant (see $mode pattern), else false (default true) * @return string $date the date part * @since 1.0 */ public function getDate($mode="time",$predefined=true) { $date = ""; if ($predefined && empty($GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_DATE_PATTERN_'.strtoupper($mode)])) return SLS_Tracing::addTrace(new Exception("Argument should be TIME| FULL_TIME | DATE | MONTH_LITTERAL | FULL_LITTERAL | FULL_LITTERAL_TIME | MONTH_LITTERAL_TIME in SLS_Date::getDate();")); $pattern = ($predefined) ? $GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_DATE_PATTERN_'.strtoupper($mode)] : $mode; for($i=0;$i<$count = strlen($pattern);$i++) { $caract = $pattern{$i}; switch($caract) { case "\\": $date .= ($i != ($count-1)) ? $pattern{($i+1)} : ''; $i++; break; case "H": $date .= $this->_hour; break; case "d": $date .= $this->_day; break; case "m": $date .= $this->_month; break; case "Y": $date .= $this->_year; break; case "F": $date .= ucfirst($this->_monthLitteral); break; case "M": $date .= ucfirst(substr($this->_monthLitteral,0,3)); break; case "l": $date .= ucfirst($this->_dayLitteral); break; case "i": $date .= $this->_minute; break; case "s": $date .= $this->_second; break; default: $date .= date($caract,SLS_Date::dateTimeToTimestamp($this->_date)); break; } } return $date; }
/** * Flush logs (monitoring & application) older than 2 months * * @access private * @since 1.0.8 */ private function flushLogs() { $date = SLS_String::substrBeforeLastDelimiter(SLS_Date::timestampToDate(strtotime("-3 month")),"-"); if (!file_exists($this->getPathConfig("logs")."monitoring")) @mkdir($this->getPathConfig("logs")."monitoring"); $handle = opendir($this->getPathConfig("logs")."monitoring"); // Foreach directories, if it's older than 2 months, delete it while (false !== ($dir = readdir($handle))) if (is_dir($this->getPathConfig("logs")."monitoring/".$dir) && substr($dir, 0, 1) != "." && ($dir <= $date)) $this->rm_recursive($this->getPathConfig("logs")."/monitoring/".$dir); $handle = opendir($this->getPathConfig("logs")); // Foreach directories, if it's older than 2 months, delete it while (false !== ($dir = readdir($handle))) if (is_dir($this->getPathConfig("logs").$dir) && substr($dir, 0, 1) != "." && $dir != "monitoring" && ($dir <= $date)) $this->rm_recursive($this->getPathConfig("logs").$dir); }