function load(&$obj, $idOrQuery, $class = "", $triggerError = FALSE) { global $dbClasses; if ($class) { if (!class_exists($class)) { $s = "Class doesn't exists: {$class}"; trigger_error($s, E_USER_WARNING); } if (is_callable(array($class, "createObject"))) { $obj = call_user_func(array($class, "createObject")); } else { $obj = new $class(); } $obj->id = $idOrQuery; if (($ret = load($obj)) && $triggerError) { $s = "Object not found in DB: class: {$class}, id: {$idOrQuery}"; trigger_error($s, E_USER_WARNING); } return $ret; } else { $idOrQueryRef = is_array($idOrQuery) ? $idOrQuery[0] : $idOrQuery; preg_match("/\\bFROM +@?(\\w+)\\b/i", $idOrQueryRef, $matches); $class = $matches[1]; if (class_exists("app{$class}")) { $class = "app{$class}"; } if (!class_exists($class)) { $s = "Class doesn't exists: {$class}"; trigger_error($s, E_USER_WARNING); } if (is_callable(array($class, "createObject"))) { $obj = call_user_func(array($class, "createObject")); } else { $obj = new $class(); } // ha a class egy olyan leszarmazott osztaly, hogy a hozza tartozo table az ososztaly neve alatt fut: if (!in_array($class, $dbClasses)) { // akkor a class nevet kicsereljuk az ososztaly nevere a query-ben: $idOrQuery = preg_replace("/\\b(FROM +@?)({$class})\\b/i", "\$1" . $obj->get_table(), $idOrQuery); } loadObjectsSql($obj, $idOrQuery, $obj); return count($obj); // ilyenkor azt adja vissza, hogy hany elemet talalt } }
function handleEnumValueChange($stack = FALSE, $oldValue = FALSE, $newValue = FALSE) { if ($stack === FALSE) { if (!isset($_POST["optionValueModificationStack"]) || !count($stack = JavaScript::jsonDecode($_POST["optionValueModificationStack"]))) { return; } // ha nem vol modositas, vagy torles } if ($oldValue !== FALSE) { // ha propagate van, nem csak azokat a modositasokat kell figyelembe venni, amik az adott modifyban tortentek, // hanem a korabbiakat is. Ezt a 'values' regi es uj ertekenek osszehasonlitasaval erjuk el. Ha talalunk olyat, // ami nincs benne az uj 'values'-ban, azt hozzaadjuk $stack-hoz egy 'delete' action-nel: $oldValueArr = splitByCommas($oldValue, FALSE); // without HTML encoding $modified = array_unique(array_map(create_function('$v', 'return $v[0]=="modify" ? $v[1] : "";'), $stack)); foreach ($oldValueArr as $val) { if (!in_array($val, $newValue) && !in_array($val, $modified)) { $stack[] = array("delete", $val); } } } if (!$stack) { return; } // ha az old es new values osszehasonlitasa utan se derul ki, hogy lett volna torles v. modositas CustomField::addCustomColumns($this->getManagedTable()); $affectedValues = array_map(create_function('$v', 'return quoteSQL(str_replace(",", ",,", $v[1]));'), $stack); $regexp = array(); $columnIndex = G::getAttr($this->id, "itemfield", "columnIndex"); foreach ($affectedValues as $v) { $regexp[] = "{$columnIndex} LIKE '%{$v}%'"; } $whereCond = " WHERE (" . implode(" OR ", $regexp) . ")"; if ($this->cid) { $whereCond .= " AND (cid={$this->cid} OR cid=0)"; } $query = "SELECT id, {$columnIndex} FROM @" . $this->getManagedTable() . $whereCond; G::load($objs, $query); $customLists = new CustomList(); $customLists->activateVariableFields(); $query = "SELECT * FROM @search {$whereCond}"; if (!loadObjectsSql($customLists, $query, $customLists)) { $objs = array_merge($objs, $customLists); } foreach ($objs as $obj) { $vals = splitByCommas($obj->{$columnIndex}, FALSE); $map = array_flip($vals); foreach ($stack as $action) { if (isset($map[$action[1]])) { // modositjuk, ha modify, uresre allitjuk, ha delete: $vals[$map[$action[1]]] = $action[0] == 'modify' ? $action[2] : ""; } } $obj->{$columnIndex} = array_filter($vals); // removes the empty values if (is_a($obj, "search")) { $obj->modify(TRUE); } else { modify($obj); } } }
function loadObjectsSQL($query, &$objArr) { return loadObjectsSql($this, $query, $objArr); }
function recalculateAllItemNums($overridePermission = FALSE) { if (!$overridePermission) { hasAdminRights($isAdm); if (!$isAdm) { handleErrorPerm(__FILE__, __LINE__); } } $cats = new AppCategory(); $query = "SELECT * FROM @category WHERE up=0"; loadObjectsSql($cats, $query, $cats); foreach ($cats as $cat) { $cat->recalculateAllItemNumsCore(); } Roll::setInfoText("itemNumbersRecalculated"); $this->nextAction =& new AppController("/"); }
function deleteColumn($field) { if ($field->isCommon) { $cidCond = ""; } else { $cidCond = " AND cid=#cid#"; } // ha nem common a custom field, amit torlunk, csak azoknak a custom listeknek az oszlopaibol kell torolni, // amik a field categoriajara specifikusak: $query = array("SELECT id, `columns`, cache FROM @search WHERE FIND_IN_SET(#id#, `columns`)!=0 {$cidCond}", "columns", $field->id, "columns", $field->cid); loadObjectsSql($lists = new CustomList(), $query, $lists); foreach ($lists as $l) { $f = preg_replace("{(,)?\\b{$this->id}\\b(?(1)|(,|\$))}", "", $l->columns); executeQuery(array("UPDATE @search SET `columns`=#f# WHERE id=#id#", "columns", $f, $l->id)); if ($l->cache) { CacheManager::resetCache($l->id, TRUE, FALSE); } } $query = array("SELECT *, '' AS str FROM @search WHERE query LIKE '%{$field->columnIndex}%' {$cidCond}", $field->cid); $lists = new CustomList(); $lists->cid = $field->cid; $lists->activateVariableFields(); loadObjectsSql($lists, $query, $lists); foreach ($lists as $l) { unset($l->{$field->columnIndex}); $l->makeSearchQuery(TRUE); modify($l); if ($l->cache) { CacheManager::resetCache($l->id, TRUE, FALSE); } } }
function delete($whereFields = "", $calledFrom = 'itemDelete') { global $gorumroll, $siteDemo; $_S =& new AppSettings(); if ($siteDemo) { return Roll::setInfoText("This operation is not permitted in the demo."); } parent::delete($whereFields); G::load($cat, $this->cid, "appcategory"); if ($calledFrom != 'categoryDelete' && $this->status) { $cat->decreaseDirectItemNum(); } $query = array("SELECT id, favorities FROM @user WHERE FIND_IN_SET(#this->id#, favorities)!=0", $this->id); $users = new User(); loadObjectsSql($users, $query, $users); foreach ($users as $u) { $f = preg_replace("{(,)?\\b{$this->id}\\b(?(1)|(,|\$))}", "", $u->favorities); executeQuery("UPDATE @user SET favorities=#f# WHERE id=#u->id#", $f, $u->id); } if ($_S->ecommerceEnabled()) { executeQuery("DELETE FROM @purchaseitem WHERE iid=#id#", $this->id); } // Ha az admin torolte ki az ad-et, akkor emailt kell kuldeni a // tulajnak: hasAdminRights($isAdm); // Ha a kategoria torleserol jutunk ide, nem kell levelet kuldeni: if ($isAdm && $calledFrom == 'itemDelete') { G::load($n, Notification_adDeleted, "notification"); if ($n->active) { if ($ownerEmail = $this->getEmailParams($params)) { $n->send($ownerEmail, $params); } } } CacheManager::resetCache($this->cid); }
function makeCustomMenu($which, $templateAttrName) { global $theme; if ($theme == "classic") { if ($which == customlist_userMenu) { $where = "displayInMenu={$which} OR displayInMenu=" . customlist_loginMenu; } elseif ($which == customlist_adminMenu) { $where = "displayInMenu={$which} OR displayInMenu=" . customlist_categoryMenu; } else { $where = "displayInMenu={$which}"; } } else { $where = "displayInMenu={$which}"; } loadObjectsSql($lists = new CustomList(), "SELECT id, listTitle, displayedFor FROM @search WHERE {$where} ORDER BY id ASC", $lists); $customMenu = array_map(array('appinit', 'customListMapper'), array_filter($lists, array('customlist', 'customListFilter'))); View::assign($templateAttrName, $customMenu); }
function resetCache($cidOrCustomListId = 0, $performReset = FALSE, $categoryId = TRUE) { static $resetForCategories = array(); if (!file_exists(CACHE_DIR)) { return; } // a program vegrehajtasa soran a $resetForCategories-be gyujtogetjuk azokat a category ID-ket, amikre a // cache-t a program vegen resetelni kell. Azert csinaljuk igy, hogy a tenyleges resetelest csak egyszer kelljen vegrehajtani if ($categoryId) { $resetForCategories[] = $cidOrCustomListId; } if ($performReset && ($count = count($resetForCategories)) || !$categoryId) { // vagy cid alapjan torlunk file-okat, vagy custom list ID alapjan: if ($categoryId) { $cidCond = $count == 1 ? "cid='{$resetForCategories['0']}'" : "FIND_IN_SET(cid, '" . implode(",", $resetForCategories) . "')!=0"; $query = "SELECT id FROM @search WHERE {$cidCond} AND cache!=0"; loadObjectsSql($lists = new CustomList(), $query, $lists); } else { $lists = array(new CustomList()); $lists[0]->id = $cidOrCustomListId; } if (count($lists) && ($d = dir(CACHE_DIR))) { $files = array(); while (false !== ($entry = $d->read())) { if (strstr($entry, ".html") || strstr($entry, ".inc")) { $files[] = $entry; } } foreach ($lists as $l) { foreach ($files as $f) { if (strstr($f, "item_search-showhtmllist-{$l->id}-")) { //FP::log("Deleting $f"); @unlink(CACHE_DIR . "/" . $f); } } } } } }
function &getListToPageAssignment() { global $gorumroll; static $listToPageAssignment = 0; if ($listToPageAssignment) { return $listToPageAssignment; } $listToPageAssignment = array_fill(0, 6, array()); loadObjectsSql($lists = new CustomList(), "SELECT * FROM @search WHERE pages!='' ORDER BY id ASC", $lists); $lists = array_filter($lists, array('customlist', 'customListFilter')); $qs = trim($gorumroll->queryString, "/"); foreach ($lists as $list) { $condArr = explode("\n", $list->pages); $composedConditionYes = array(); // ha a customlist "details" page-et nezzuk, ne legyen rajta a list meg egyszer: $composedConditionNo = array("\$qs=='customlist/{$list->id}'"); foreach ($condArr as $condPiece) { $condPiece = trim(str_replace("'", "", $condPiece)); if ($not = $condPiece[0] == "!") { $condPiece = substr($condPiece, 1); } $condPiece = trim($condPiece, "/"); if (strstr($condPiece, "*")) { $condPiece = str_replace("*", "[^/]*", $condPiece); $condPiece = "preg_match('{" . $condPiece . "}', \$qs)"; } else { $condPiece = "\$qs=='{$condPiece}'"; } if ($not) { $composedConditionNo[] = $condPiece; } else { $composedConditionYes[] = $condPiece; } } $composedCondition = implode(" || ", $composedConditionYes); if ($composedCondition) { $composedCondition = "({$composedCondition}) && "; } $composedCondition .= "!(" . implode(" || ", $composedConditionNo) . ")"; //echo("$qs<br>$composedCondition<br>"); eval("\$cond = {$composedCondition};"); if ($cond) { if ($list->listStyle == customlist_normal) { $positionAttr = "positionNormal"; } elseif ($list->listStyle == customlist_scrollable) { $positionAttr = "positionScrollable"; } foreach (explode(",", $list->{$positionAttr}) as $position) { $listToPageAssignment[$position][] = $list->id; } } } CustomList::addSidebarDependentCss($listToPageAssignment); return $listToPageAssignment; }