Esempio n. 1
0
 function tagForeach($Item = array())
 {
     if (!$this->is("[data-template]")) {
         $this->addTemplate();
     }
     $srcItem = $Item;
     $pagination = "";
     $sort = $this->attr("sort");
     $dsort = $this->attr("data-sort");
     $pagination = "ajax";
     if ($this->attr("data-pagination") > "") {
         $size = $this->attr("data-pagination");
         $pagination = "js";
     }
     if ($this->attr("data-size") > "") {
         $size = $this->attr("data-size");
         $pagination = "ajax";
     } else {
         $size = "false";
     }
     $mode = $this->attr("mode");
     $dmode = $this->attr("data-mode");
     if ($dmode == "") {
         $dmode = "list";
     }
     $desc = $this->attr("desc");
     $ddesc = $this->attr("data-desc");
     $rand = $this->attr("rand");
     $step = $this->attr("step");
     $page = $this->attr("data-page");
     if ($page == "") {
         $page = 1;
     }
     $cache = $this->attr("data-cache");
     $dList = $this->attr("data-list");
     if ($dList == "") {
         $dList = false;
     } else {
         $dList = aikiReadList($dList);
     }
     $limit = $this->attr("limit");
     $call = $this->attr("call");
     $oconv = $this->attr("oconv");
     $item = $this->attr("item");
     $where = $this->attr("where");
     if ($where == "") {
         $where = NULL;
     }
     $field = $this->attr("field");
     $from = $this->attr("from");
     $find = $this->attr("data-find");
     // контекстный поиск
     $tplid = $this->attr("data-template");
     $beforeShow = $this->attr("data-before-show");
     if ($from > "" && !isset($Item[$from])) {
         $tmp = "";
         eval('$tmp=$Item' . $from . ";");
         if ($tmp > "") {
             $Item[$from] = $tmp;
         }
     }
     if ($from > "" && isset($Item[$from]) && $this->hasRole("foreach") && $cache == "") {
         if ($this->attr("form") == "" && isset($Item["form"])) {
             $form = $Item["form"];
         } else {
             $form = "";
         }
         if ($this->attr("item") == "" && isset($Item["id"])) {
             $item = $Item["id"];
         } else {
             $item = "";
         }
         $Item = $Item[$from];
         if (!is_array($Item)) {
             $Item = json_decode($Item, true);
         }
         if ($field > "") {
             $Item = $Item[$field];
         }
         if (!is_array($Item)) {
             $Item = json_decode($Item, true);
         }
         if ($where > "") {
             $Item = aikiWhere($Item);
         }
     } else {
         $Item = array();
     }
     $vars = $this->attr("vars");
     if ($vars > "") {
         $Item = attrAddData($vars, $Item);
     }
     $json = $this->attr("json");
     if ($json > "") {
         $Item = json_decode($json, true);
     }
     $index = $this->attr("index");
     if (($this->attr("form") > "" or $this->attr("data-form") > "") && $from == "" && $cache == "") {
         $form = $this->attr("form");
         if ($form == "") {
             $form = $this->attr("data-form");
         }
         $type = $this->attr("data-type");
         if ($type > "") {
             $_SESSION[$form]["data-type-tmp"] = $type;
         }
         formCurrentInclude($form);
         $datatype = "file";
         $func = $form . "DataType";
         if (is_callable($func)) {
             $datatype = $func();
         }
         if ($item > "") {
             $Item[0] = aikiReadItem($form, $item);
             if ($field > "") {
                 $Item = $Item[0][$field];
                 if (is_string($Item)) {
                     $Item = json_decode($Item, true);
                 }
                 if (isset($Item[0]["img"]) && isset($Item[0]["visible"])) {
                     $Item = array_filter_value($Item, "visible", "1");
                 }
             }
         } else {
             $list = aikiListItems($form, $where);
             $Item = array();
             $Item = $list["result"];
         }
     }
     if (is_string($Item)) {
         $Item = json_decode($Item, true);
     }
     if (!is_array($Item)) {
         $Item = array($Item);
     }
     if ($cache > "" && isset($_SESSION["data"]["foreach"][$cache])) {
         $Item = $_SESSION["data"]["foreach"][$cache];
         $first = array_shift($Item);
         array_unshift($Item, $first);
         if (isset($first["form"])) {
             $form = $first["form"];
             formCurrentInclude($form);
         }
     }
     if ($sort > "") {
         // старый формат
         if ($desc == "true") {
             $stype = SORT_DESC;
         } else {
             $stype = SORT_ASC;
         }
         $Item = array_sort($Item, $sort, $stype);
     }
     if ($dsort > "") {
         $Item = array_sort_multi($Item, $dsort);
         if ($cache !== "") {
             $_SESSION["data"]["foreach"][$cache] = $Item;
         }
     }
     if ($ddesc == "true") {
         $Item = array_reverse($Item);
     }
     if ($rand == "true") {
         shuffle($Item);
     }
     if (is_callable($call)) {
         $Item = $call($Item);
     }
     $tpl = $this->innerHtml();
     $inner = "";
     $this->html("");
     if ($step > 0) {
         $steptpl = $this->clone();
         $stepcount = 0;
     }
     if ($tplid == "") {
         $tplid = "tpl" . newIdRnd();
     }
     $ndx = 0;
     $fdx = 0;
     $n = 0;
     $count = count($Item);
     if ($size == "false") {
         $pagination = "js";
     }
     if ($this->tag() !== "select" && $size == "" && $count > 200) {
         $pagination = "ajax";
         $size = 10;
         $page = 1;
         $this->attr("data-size", $size);
     }
     if ($count && $Item !== array(0 => "")) {
         $cacheList = array();
         $inner = "";
         $srcVal = array();
         foreach ($srcItem as $k => $v) {
             $srcVal["%{$k}"] = $v;
         }
         unset($v);
         $ndx = 0;
         $n = 0;
         $f = 0;
         $tmptpl = aikiFromString($tpl);
         foreach ($Item as $key => $val) {
             if (!isset($val["id"])) {
                 $lid = $key;
             } else {
                 $lid = $val["id"];
             }
             if ($dList == false or in_array($lid, $dList)) {
                 $n++;
                 $cacheVal = $val;
                 if ($limit == "" or $limit * 1 > $ndx * 1) {
                     if (!is_array($val)) {
                         $tmp = json_decode($val, true);
                         if ($tmp) {
                             $val = $tmp;
                         } else {
                             $val = array($val);
                         }
                     }
                     // именно так и никак иначе
                     if ($vars > "") {
                         $val = attrAddData($vars, $val);
                     }
                     if ($val !== NULL && ($where == NULL or aikiWhereItem($val, $where))) {
                         // если не обнулено в вызываемой ранее функцией (например, если стоит флаг скрытия в списке)
                         if ($cache == "" && $size !== "false" && $size !== "") {
                             $cacheList[$key] = $cacheVal;
                         }
                         if ($pagination == "ajax" && ($size == "false" or $size == "")) {
                             $size = 999999999;
                         }
                         if ($pagination == "ajax" and ($size > "" && $cache > "" && ($n > $page * $size - $size && $n <= $page * $size) or $size > "" && $cache == "" && $ndx < $size or $find > "") or $size == "" or $pagination == "js") {
                             $itemform = "";
                             if (isset($val["form"])) {
                                 $itemform = $val["form"];
                             } else {
                                 $itemform = $_GET["form"];
                             }
                             $text = $tmptpl->clone();
                             $val = (array) $srcVal + (array) $val;
                             // сливаем массивы
                             if ($beforeShow !== "false") {
                                 $val = aikiBeforeShowItem($val, $dmode, $itemform);
                             }
                             if (is_callable($oconv)) {
                                 $val = $oconv($val);
                             }
                             $text->find(":first")->attr("idx", $key);
                             $val["_idx"] = $_SESSION["foreach_idx"] = $key;
                             $val["_ndx"] = $_SESSION["foreach_ndx"] = $ndx;
                             $val["_num"] = $_SESSION["foreach_num"] = $ndx + 1;
                             $text->contentSetData($val);
                             if ($find == "") {
                                 $flag = true;
                             } else {
                                 $flag = aikiInString(strip_tags($text->innerHtml()), $find);
                                 if ($flag) {
                                     $f++;
                                 }
                             }
                             if ($find == "" or $size == "false" or $size == "" or $find > "" && ($f > $page * $size - $size && $f <= $page * $size)) {
                                 $tmp;
                             } else {
                                 $flag = false;
                             }
                             if ($flag == true) {
                                 $ndx++;
                                 if ($step > 0) {
                                     // если степ, то работаем с объектом
                                     if ($stepcount == 0) {
                                         $t_step = $steptpl->clone();
                                         $t_step->addClass($tplid);
                                         $this->append($t_step);
                                     }
                                     $this->find(".{$tplid}:last")->append(clearValueTags($text->outerHtml()));
                                     $stepcount++;
                                     //$stepcount=$this->find(".{$tplid}:last")->children()->length;
                                     if ($stepcount == $step) {
                                         $stepcount = 0;
                                     }
                                 } else {
                                     // иначе строим строку
                                     $inner .= clearValueTags($text->outerHtml());
                                 }
                             } else {
                                 $n--;
                             }
                             $text->remove();
                         }
                     }
                 }
             }
         }
         if ($step > 0) {
             foreach ($this->find(".{$tplid}") as $tid) {
                 $tid->removeClass($tplid);
             }
             unset($tid);
         } else {
             $this->html($inner);
         }
         unset($val, $ndx, $t_step, $string, $text, $func, $inner, $tmptpl);
     }
     if ($this->tag() == "select") {
         if (!is_array($result)) {
             $this->outerHtml("");
         }
         $plhr = $this->attr("placeholder");
         if ($plhr > "") {
             $this->prepend("<option value=''>{$plhr}</option>");
         }
     } else {
         $data_group = $this->attr("data-group");
         $data_total = $this->attr("data-total");
         if ($data_total > "" or $data_group > "") {
             aikiTableProcessor($this);
             $size = "";
         }
         if ($size > "" && $size !== "false" && $pagination == "js") {
             $this->tagDataPagination($size);
         }
         if ($size > "" && $size !== "false" && $pagination == "ajax") {
             if ($cache > "") {
                 $cacheId = $cache;
             } else {
                 $cacheId = md5($from . $form . $where . $tplid . $sort . $rand . $dsort . $limit . $item . $field . $call . $oconv . $vars . $json . implode("-", $_GET));
             }
             if ($cache == "" && isset($cacheList)) {
                 $_SESSION["data"]["foreach"][$cacheId] = $cacheList;
             }
             unset($cacheList);
             if ($find > "") {
                 $count = $f;
             } else {
                 $count = count($_SESSION["data"]["foreach"][$cacheId]);
             }
             $pages = ceil($count / $size);
             //if (round($pages)<$pages) {$pages=round($pages)+1;}
             $this->tagDataPagesAjax($size, $page, $pages, $cacheId, $count, $find);
         }
     }
     unset($Item, $tpl);
     gc_collect_cycles();
 }
Esempio n. 2
0
function jdbListItems($form, $where = NULL, $engine = FALSE)
{
    if (mysqlCheckTable("jdb")) {
        $func = $form . "MysqlListItems";
        if (is_callable($func)) {
            $out['result'] = $func();
        } else {
            $SQL = "select * from jdb WHERE form = '{$form}';";
            $func = $form . "BeforeGetListItems";
            if (is_callable($func)) {
                $SQL = $func($SQL);
            }
            $result = $_SESSION["mysql"]->query($SQL) or die("Query failed (jdbListItems): " . mysqli_error($_SESSION["mysql"]));
            $array = array();
            while ($data = mysqli_fetch_array($result)) {
                $array[] = json_decode($data["json"], true);
            }
            unset($data);
            if ($where != NULL) {
                $result = aikiWhere($array, $where);
            }
            $after = "_" . $form . "AfterGetListItems";
            if (is_callable($after)) {
                $array = $after($array);
            }
            $after = $form . "AfterGetListItems";
            if (is_callable($after)) {
                $array = $after($array);
            }
            $out['result'] = $array;
        }
    } else {
        echo "Error: 'jdb' table is not present!";
        $out["result"] = array();
    }
    if (!is_array($out["result"])) {
        $out["result"] = array();
    }
    return $out;
}