/** * Handle on_project_user_removed event * * @param Project $project * @param User $user * @return null */ function resources_handle_on_project_user_removed($project, $user) { $rows = db_execute('SELECT id FROM ' . TABLE_PREFIX . 'project_objects WHERE project_id = ?', $project->getId()); if (is_foreachable($rows)) { $object_ids = array(); foreach ($rows as $row) { $object_ids[] = (int) $row['id']; } // foreach $user_id = $user->getId(); // Assignments cleanup db_execute('DELETE FROM ' . TABLE_PREFIX . 'assignments WHERE user_id = ? AND object_id IN (?)', $user_id, $object_ids); cache_remove('object_starred_by_' . $user_id); cache_remove('object_assignments_*'); cache_remove('object_assignments_*_rendered'); // Starred objects cleanup db_execute('DELETE FROM ' . TABLE_PREFIX . 'starred_objects WHERE user_id = ? AND object_id IN (?)', $user_id, $object_ids); cache_remove('object_starred_by_' . $user_id); // Subscriptions cleanup db_execute('DELETE FROM ' . TABLE_PREFIX . 'subscriptions WHERE user_id = ? AND parent_id IN (?)', $user_id, $object_ids); cache_remove('user_subscriptions_' . $user_id); // remove pinned project PinnedProjects::unpinProject($project, $user); } // if }
/** * Do save data collected in this request in database * * @param void * @return boolean */ function save() { $date = db_escape(date(DATETIME_MYSQL)); $for_drop = array(); $for_insert = array(); $user_ids = array(); foreach ($_SESSION['project_object_views'] as $object_id => $users) { foreach ($users as $user_id => $user) { $object_id = (int) $object_id; $user_id = (int) $user_id; if (!in_array($user_id, $user_ids)) { $user_ids[] = $user_id; } // if if ($object_id && $user_id) { $for_drop[] = "(object_id = '{$object_id}' AND created_by_id = '{$user_id}')"; $name = db_escape($user['name']); $email = db_escape($user['email']); $for_insert[] = "({$object_id}, {$user_id}, {$name}, {$email}, {$date})"; } // if } // foreachs } // foreach if (is_foreachable($for_drop)) { db_execute('DELETE FROM ' . TABLE_PREFIX . 'project_object_views WHERE ' . implode(' OR ', $for_drop)); } // if if (is_foreachable($for_insert)) { return db_execute('INSERT INTO ' . TABLE_PREFIX . 'project_object_views (object_id, created_by_id, created_by_name, created_by_email, created_on) VALUES ' . implode(', ', $for_insert)); } // if // Clear cache... foreach ($user_ids as $user_id) { cache_remove("object_viewed_by_{$user_id}"); } // foreach }
function remove_bookmark($userid, $codeid) { $db = getdb(); if (!$db) { return false; } $uidesc = $db->escape_string($userid); $sql = 'delete from ' . DB_TABLE . "_users where codeid = '{$codeid}' and userid = '{$uidesc}'"; $res = $db->query($sql); if ($res && $db->affected_rows > 0) { cache_remove($userid, 'user'); return true; } return false; }
/** * Delete Project Icon * * @param void * @return null */ function delete_icon() { if ($this->active_project->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if (!$this->active_project->canEdit($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if if ($this->request->isSubmitted()) { unlink($this->active_project->getIconPath()); unlink($this->active_project->getIconPath(true)); cache_remove('project_icons'); if ($this->request->isAsyncCall()) { $this->serveData(array('message' => lang('Icon successfully removed'), 'icon' => $this->active_project->getIconUrl(true)), 'delete', null, FORMAT_JSON); } else { $this->redirectToUrl($this->active_project->getEditIconUrl()); } } else { $this->httpError(HTTP_ERR_BAD_REQUEST); } // if }
/** * Drop user cache * * @param User $user * @return null */ function dropUserCache($user) { cache_remove('user_pinned_projects_' . $user->getId(), $value); }
function move() { $new_parent_id = $this->request->post('new_parent_id'); $new_parent_type = $this->request->post('new_parent_type'); $new_parent_url = ''; $move_mode = false; if (!empty($new_parent_id) && !empty($new_parent_type)) { $move_mode = true; $parent_obj = $sql_part = null; switch ($new_parent_type) { case 'milestone': $parent_obj = new MileStone($new_parent_id); break; case 'ticket': $parent_obj = new Ticket($new_parent_id); break; case 'page': $parent_obj = new Page($new_parent_id); break; } if ($parent_obj) { $body = $this->active_task->getBody(); $doc = new DOMDocument(); if ($doc->loadHTML($body)) { $anc_tags = $doc->getElementsByTagName('a'); $new_parent_url = ''; foreach ($anc_tags as $anc) { if ($anc->nodeValue == 'View Task in Full') { $href = $anc->getAttribute('href'); $fragment = substr($href, strpos($href, '#')); $anc->setAttribute('href', $parent_obj->getViewUrl() . $fragment); break; } } if (!empty($fragment)) { $body_tag = $doc->getElementsByTagName('body'); $body = $doc->saveXML($body_tag->item(0)->firstChild); $comment_id = str_replace('#comment', '', $fragment); } } $link = mysql_connect(DB_HOST, DB_USER, DB_PASS); mysql_select_db(DB_NAME); $query = "update \n\t\t\t\t\t\t\thealingcrystals_project_objects \n\t\t\t\t\t\t set \n\t\t\t\t\t\t\tproject_id='" . $parent_obj->getProjectId() . "', \n\t\t\t\t\t\t\tmilestone_id='" . $parent_obj->getMilestoneId() . "', \n\t\t\t\t\t\t\tparent_id='" . $parent_obj->getId() . "', \n\t\t\t\t\t\t\tparent_type='" . $parent_obj->getType() . "', \n\t\t\t\t\t\t\tbody = '" . mysql_real_escape_string($body) . "' \n\t\t\t\t\t\t where\tid='" . $this->active_task->getId() . "'"; mysql_query($query, $link); if (!empty($comment_id)) { $comment_query = "update \n\t\t\t\t\t\t\thealingcrystals_project_objects \n\t\t\t\t\t\t set \n\t\t\t\t\t\t\tproject_id='" . $parent_obj->getProjectId() . "', \n\t\t\t\t\t\t\tmilestone_id='" . $parent_obj->getMilestoneId() . "', \n\t\t\t\t\t\t\tparent_id='" . $parent_obj->getId() . "', \n\t\t\t\t\t\t\tparent_type='" . $parent_obj->getType() . "', \n\t\t\t\t\t\t\tposition=null\n\t\t\t\t\t\t where\tid='" . $comment_id . "'"; mysql_query($comment_query, $link); } mysql_close($link); $new_parent_url = $parent_obj->getViewUrl() . '#task' . $this->active_task->getId(); $cache_id = TABLE_PREFIX . 'project_objects_id_' . $this->active_task->getId(); $cache_obj = cache_get($cache_id); if ($cache_obj) { cache_remove($cache_id); } } } else { $listing = array(); switch ($this->active_task_parent->getType()) { case 'Milestone': //$listing = Milestones::findByProject($this->active_project, $this->logged_user); $listing = Milestones::findActiveByProject_custom($this->active_project); break; case 'Ticket': $listing = Tickets::findOpenByProjectByNameSort($this->active_project, STATE_VISIBLE, $this->logged_user->getVisibility()); break; case 'Page': $categories = Categories::findByModuleSection($this->active_project, 'pages', 'pages'); $listing = Pages::findByCategories($categories, STATE_VISIBLE, $this->logged_user->getVisibility()); /*foreach($categories as $category){ $listing = array_merge($listing, Pages::findByCategory($category, STATE_VISIBLE, $this->logged_user->getVisibility())); }*/ break; } $this->smarty->assign(array('teams' => Projects::findNamesByUser($this->logged_user), 'listing' => $listing, 'task_parent_id' => $this->active_task_parent->getId())); } $this->smarty->assign('new_parent_url', $new_parent_url); $this->smarty->assign('move_mode', $move_mode); }
/** * Delete specific object (and related objects if neccecery) * * @param void * @return boolean */ function delete() { if ($this->isNew()) { return false; } // if $cache_id = $this->getCacheId(); event_trigger('on_before_object_deleted', array('object' => &$this)); $delete = $this->doDelete(); if ($delete && !is_error($delete)) { $this->setNew(true); $this->setLoaded(false); cache_remove($cache_id); event_trigger('on_object_deleted', array('object' => &$this)); } // if return $delete; }
/** * Delete option from database * * @param string $name * @return boolean */ function removeOption($name) { $delete = ConfigOptions::delete(array('name = ?', $name)); if ($delete && !is_error($delete)) { cache_remove(TABLE_PREFIX . 'config_options_name_' . $name); } // if return $delete; }
function check_alt_user_id($userid, $alt_userid) { $db = getdb(); if (!$db) { return; } $uidesc = $db->escape_string($userid); $alt_uidesc = $db->escape_string($alt_userid); $sql = 'select * from ' . DB_TABLE . "_usermap where (userid = '{$uidesc}' and puserid = '{$alt_uidesc}') or (userid = '{$alt_uidesc}' and puserid = '{$uidesc}')"; $res = $db->query($sql); if (!$res) { return; } if (!$res->num_rows) { $sql = 'insert into ' . DB_TABLE . "_usermap (userid, puserid) values ('{$alt_uidesc}', '{$uidesc}')"; $db->query($sql); } cache_remove($userid, 'user'); cache_remove($alt_userid, 'user'); }
/** * Copy project items into a destination project * * @param Project $to * @return null */ function copyItems(&$to) { // Prepare time diff $source_starts_on = $this->getStartsOn(); if (!instance_of($source_starts_on, 'DateValue')) { $source_starts_on = $this->getCreatedOn(); } // if $target_starts_on = $to->getStartsOn(); if (!instance_of($target_starts_on, 'DateValue')) { $target_starts_on = $to->getCreatedOn(); } // if $diff = $target_starts_on->getTimestamp() - $source_starts_on->getTimestamp(); // Migrate project users $project_users = ProjectUsers::findByProject($this); if (is_foreachable($project_users)) { foreach ($project_users as $project_user) { if ($to->getLeaderId() != $project_user->getUserId()) { $user = $project_user->getUser(); if (instance_of($user, 'User')) { $to->addUser($user, $project_user->getRole(), $project_user->getPermissions()); } // if } // if } // foreach } // if // We need to move milestones in order to get milestones map $milestones_map = null; $milestones = Milestones::findAllByProject($this, VISIBILITY_PRIVATE); if (is_foreachable($milestones)) { $milestones_map = array(); foreach ($milestones as $milestone) { $copied_milestone = $milestone->copyToProject($to); if (instance_of($copied_milestone, 'Milestone')) { $copied_milestone->advance($diff, true); $milestones_map[$milestone->getId()] = $copied_milestone; } // if } // foreach } // if // Now move categories $categories_map = null; $categories = Categories::findByProject($this); if (is_foreachable($categories)) { foreach ($categories as $category) { $copied_category = $category->copyToProject($to, null, null, false); if (instance_of($copied_category, 'Category')) { $categories_map[$category->getId()] = $copied_category; } // if } // foreach } // if // Let the modules to their thing event_trigger('on_copy_project_items', array(&$this, &$to, $milestones_map, $categories_map)); // Now, lets update due dates $completable_types = get_completable_project_object_types(); if (is_foreachable($completable_types)) { foreach ($completable_types as $k => $type) { if (strtolower($type) == 'milestone') { unset($completable_types[$k]); } // if } // foreach if (count($completable_types) > 0) { $rows = db_execute_all('SELECT id, due_on FROM ' . TABLE_PREFIX . 'project_objects WHERE project_id = ? AND type IN (?) AND due_on IS NOT NULL', $to->getId(), $completable_types); if (is_foreachable($rows)) { foreach ($rows as $row) { $id = (int) $row['id']; $new_date = date(DATE_MYSQL, strtotime($row['due_on']) + $diff); db_execute('UPDATE ' . TABLE_PREFIX . 'project_objects SET due_on = ? WHERE id = ?', $new_date, $id); cache_remove("acx_project_objects_id_{$id}"); } // foreach } // if } // if } // if // Refresh tasks count, just in case... $to->refreshTasksCount(); }
/** * Clear all user permissions / project related chaches * * @param User $user * @return null */ function clean_user_permissions_cache($user) { cache_remove('visible_types_filter_for_' . $user->getId()); cache_remove('visible_project_types_filter_for_' . $user->getId()); cache_remove('visible_project_types_for_' . $user->getId()); }
/** * Drop user subscription cache * * @param User $user * @return null */ function dropUserCache($user) { cache_remove('user_subscriptions_' . $user->getId()); }
/** * Delete all values by config option name * * @param string $name * @return boolean */ function deleteByOption($name) { $result = db_execute_all('SELECT user_id FROM ' . TABLE_PREFIX . 'user_config_options WHERE name = ?', $name); if (is_foreachable($result)) { foreach ($result as $row) { cache_remove('user_config_options_' . $row['user_id']); } // foreach } // if return db_execute('DELETE FROM ' . TABLE_PREFIX . 'user_config_options WHERE name = ?', $name); }
/** * Delete assignments by User * * @param User $user * @return boolean */ function deleteByUser($user) { cache_remove('user_assignments_' . $user->getId()); return Assignments::delete(array('user_id = ?', $user->getId())); }
function closeTab() { $id = (int) get('id', 0, 'pg'); $elem_id = get('elem_id', -1, 'pg'); $esId = $this->getesId(); $fld = array_key_exists('fld', $_POST) ? $_POST['fld'] : array(); $wc = $this->handleChanges($id, $esId, $fld, $elem_id); // сохранение в сесиию $this->saveWC($id, $esId, $wc); $act = get('act2', '', 'pg'); // новая вкладка if ($act == 'newTab') { return $this->newTab($id, $esId); } // сохранение изменений if ($act == 'save' || $act == 'apply') { $save = $this->save($id, $esId, $wc); //------------------------------------------------------------------------------ // добавляем возможность вызова какой-либо функции перед закрытием редактора // передается в get или post как "last" $oed_vars = cache_get($this->oed_query_cache_id); if (!empty($oed_vars['last'])) { $func = $oed_vars['last']; $params = array('id' => $id, 'esId' => $esId, 'wc' => array(get('tab', '0', 'p') => $wc), 'insIds' => $this->insIds, 'query' => $oed_vars); $text = $this->{$func}($params); if (isset($text['error']) && $text['error'] == true) { $save = $text['message']; } } if ($act == 'save') { cache_remove($this->oed_query_cache_id); } //------------------------------------------------------------------------------ return $save; } // отмена изменений if ($act == 'cancel') { $this->clearSession($id, $esId); return "<script>if (top.opener && top.opener.focusItem) top.opener.focusItem(); window.top.close();</script>"; } }
/** * Uninstall * * @param void * @return null */ function uninstall() { if ($this->request->isSubmitted()) { if ($this->active_module->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if (!$this->active_module->canBeUninstalled()) { flash_error(':name module cannot be uninstalled', array('name' => $this->active_module->getName())); $this->redirectToReferer(assemble_url('admin_modules')); } // if $uninstall = $this->active_module->uninstall(); if ($uninstall && !is_error($uninstall)) { cache_remove('all_modules'); flash_success(':name module is uninstalled', array('name' => Inflector::humanize($this->active_module->getName()))); } else { flash_error('Failed to uninstall :name module', array('name' => Inflector::humanize($this->active_module->getName()))); } // if $this->redirectToUrl($this->active_module->getViewUrl()); } else { $this->httpError(HTTP_ERR_BAD_REQUEST); } // if }
/** * Delete this company from database * * @param void * @return boolean */ function delete() { db_begin_work(); $delete = parent::delete(); if ($delete && !is_error($delete)) { cache_remove('companies_id_name'); // remove ID - name map from cache $users = $this->getUsers(); if (is_foreachable($users)) { foreach ($users as $user) { $user->delete(); } // foreach } // if Projects::resetByCompany($this); db_commit(); } else { db_rollback(); } // if return $delete; }
function cache_load($srcpath, $thumbw, $thumbh) { global $cfg, $imgIsRemote; cache_clear(); // Setup if ($imgIsRemote) { $srctime = time(); } else { $srctime = @filemtime($srcpath); } if (!$srctime) { return false; } // Get data $data = fr("cache/cacheData.txt"); if ($data) { $data = explode("####\r\n", $data); } else { $data = array(); } // Search data for ($i = count($data); $i >= 0; $i--) { $values = explode("##", $data[$i]); if ($srcpath == $values[0] && $thumbw == $values[2] && $thumbh == $values[3]) { if ($srctime >= $values[4]) { cache_log("CACHE_RENEW :: " . $srcpath); cache_remove($srcpath); return false; } if (!file_exists($values[1])) { cache_remove($srcpath); return false; } cache_log("CACHE_LOAD :: " . $srcpath); return $values[1]; } } return false; }