Exemplo n.º 1
0
 function makeSQL($sql)
 {
     $db = JFactory::getDBO();
     $parser = new FSSParser();
     $parser->template = $sql;
     $user = JFactory::getUser();
     $parser->setVar('user_id', $user->id);
     $parser->setVar('username', $user->username);
     foreach ($this->filter as $filter) {
         if (isset($filter->type) && $filter->type == "daterange") {
             $replace = 1;
             $to = FSS_Input::getString("{$filter->name}_to", $this->getDateRangeTo($filter));
             $from = FSS_Input::getString("{$filter->name}_from", $this->getDateRangeFrom($filter));
             $find = "{" . $filter->name . "_from}";
             $replace = FSSJ3Helper::getEscaped($db, $from);
             //$sql = str_replace($find, $replace, $sql);
             $parser->SetVar($filter->name . "_from", $replace);
             $find = "{" . $filter->name . "_to}";
             $replace = FSSJ3Helper::getEscaped($db, $to);
             //$sql = str_replace($find, $replace, $sql);
             $parser->SetVar($filter->name . "_to", $replace);
             // need to filter the column by the date rand selected
         } elseif (isset($filter->type) && $filter->type == "date") {
             $replace = 1;
             $date = FSS_Input::getString("{$filter->name}", date("Y-m-d"));
             $find = "{" . $filter->name . "}";
             $replace = FSSJ3Helper::getEscaped($db, $date);
             $parser->SetVar($filter->name, $replace);
             // need to filter the column by the date rand selected
         } elseif (isset($filter->type) && $filter->type == "lookup") {
             $value = FSS_Input::getString('filter_' . $filter->name, '');
             $find = "{" . $filter->name . "}";
             if ($value == "") {
                 //$parser->SetVar($find, "1");
             } else {
                 $replace = " {$filter->field} = '" . FSSJ3Helper::getEscaped($db, $value) . "' ";
                 //$sql = str_replace($find, $replace, $sql);
                 $parser->SetVar($filter->name, $replace);
             }
         } else {
             $value = FSS_Input::getString('filter_' . $filter->name, $filter->default);
             if (!empty($filter->options) && array_key_exists($value, $filter->options)) {
                 $option = $filter->options[$value];
                 $find = "{" . $filter->name . "}";
                 $replace = $option->value;
             } else {
                 $replace = "";
             }
             //$sql = str_replace($find, $replace, $sql);
             $parser->SetVar($filter->name, $replace);
         }
     }
     foreach ($this->group as $group) {
         $find = "{" . $group->name . "}";
         $find_disp = "{" . $group->name . "_disp}";
         if ($group->type == "dategroup") {
             $value = FSS_Input::getString('group_' . $group->name, 'day');
             $replace = "DATE({$group->field})";
             $replace_disp = "DATE({$group->field})";
             switch ($value) {
                 case 'week':
                     $replace = "week";
                     $replace_disp = "CONCAT(YEAR({$group->field}), ' week ', WEEK({$group->field}))";
                     break;
                 case 'month':
                     $replace = "month";
                     $replace_disp = "CONCAT(MONTHNAME({$group->field}), ' ', YEAR({$group->field}))";
                     break;
                 case 'year':
                     $replace = "year";
                     $replace_disp = "YEAR({$group->field})";
                     break;
             }
         }
         //$sql = str_replace($find, $replace, $sql);
         //$sql = str_replace($find_disp, $replace_disp, $sql);
         $parser->SetVar($group->name, $replace);
         $parser->SetVar($group->name . "_disp", $replace_disp);
     }
     $final_sql = $parser->Parse();
     $final_sql = str_replace("#__", FSS_Helper::dbPrefix(), $final_sql);
     $this->vars = $parser->vars;
     return $final_sql;
 }
Exemplo n.º 2
0
 function RestoreData(&$data)
 {
     global $log;
     $db = JFactory::getDBO();
     /*echo "<pre>";
     		print_r($data);
     		echo "<pre>";  
     	
     		exit;*/
     foreach ($data as $table => $stuff) {
         $tabler = str_replace('jos_', FSS_Helper::dbPrefix(), $table);
         //$table =
         // auto import of lite module stuff
         if (strpos($tabler, "fsf") > 0) {
             $tabler = str_replace("fsf", "fss", $tabler);
         }
         if (strpos($tabler, "fst") > 0) {
             $tabler = str_replace("fst", "fss", $tabler);
         }
         if (array_key_exists('data', $stuff)) {
             $qry = "TRUNCATE `{$tabler}`";
             $log .= $qry . "\n";
             $db->setQuery($qry);
             $db->Query();
             $log .= "\n\nProcessing table " . $table . " as {$tabler}\n";
             $log .= $this->RestoreTableData($tabler, $stuff, true);
         }
     }
 }