/** * Return manager instance * * @access protected * @param void * @return ProjectLinks */ function manager() { if (!$this->manager instanceof ProjectLinks) { $this->manager = ProjectLinks::instance(); } return $this->manager; }
/** * Delete project link * * @param void * @return null */ function delete_link() { $project_link = ProjectLinks::findById(get_id()); if (!ProjectLink::canEdit(logged_user())) { flash_error(lang('no access permissions')); $this->redirectTo('links', 'index'); } // if if (!$project_link instanceof ProjectLink) { flash_error(lang('project link dnx')); $this->redirectTo('links'); } // if try { DB::beginWork(); $project_link->delete(); ApplicationLogs::createLog($project_link, active_project(), ApplicationLogs::ACTION_DELETE); DB::commit(); flash_success(lang('success delete link', $project_link->getTitle())); $this->redirectTo('links'); } catch (Exception $e) { DB::rollback(); tpl_assign('error', $e); } // try }
/** * This function will return paginated result. Result is an array where first element is * array of returned object and second populated pagination object that can be used for * obtaining and rendering pagination data using various helpers. * * Items and pagination array vars are indexed with 0 for items and 1 for pagination * because you can't use associative indexing with list() construct * * @access public * @param array $arguments Query argumens (@see find()) Limit and offset are ignored! * @param integer $items_per_page Number of items per page * @param integer $current_page Current page number * @return array */ function paginate($arguments = null, $items_per_page = 10, $current_page = 1) { if (isset($this) && instance_of($this, 'ProjectLinks')) { return parent::paginate($arguments, $items_per_page, $current_page); } else { return ProjectLinks::instance()->paginate($arguments, $items_per_page, $current_page); } // if }
/** * Show and process edit link logo form * * @param void * @return null */ function edit_logo() { $link = ProjectLinks::findById(get_id()); if (!($link instanceof ProjectLink)) { flash_error(lang('link dnx')); $this->redirectToReferer(get_url('links', 'index')); } // if if (!$link->canEdit(logged_user())) { flash_error(lang('no access permissions')); $this->redirectToReferer(get_url('links')); } // if if (!function_exists('imagecreatefromjpeg')) { flash_error(lang('no image functions')); $this->redirectTo('links'); } // if $this->setTemplate('edit_logo'); //$this->setLayout('administration'); tpl_assign('link', $link); $logo = array_var($_FILES, 'new_logo'); if (is_array($logo)) { try { $uploaded_file_size = array_var($logo, 'size', 0); if ($uploaded_file_size == 0) { $x1 = 0 + array_var($_POST, 'x1'); $y1 = 0 + array_var($_POST, 'y1'); $x2 = 0 + array_var($_POST, 'x2'); $y2 = 0 + array_var($_POST, 'y2'); $url = $link->getUrl(); if (!string_begins_with($url, 'http://')) $url = 'http://' . $url; //die("$x1 $y1 $x2 $y2 $url"); $img_data = get_content_from_url('wimg.ca', 80, $url); if ($img_data) { $src_img = imagecreatefromstring($img_data); $dst_img = imagecreatetruecolor(50, 50); imagecopyresized($dst_img, $src_img, 0, 0, $x1, $y1, 50, 50, abs($x2-$x1), abs($y2-$y1) ); // Output and free from memory //header('Content-Type: image/png'); $tempname = tempnam(ROOT . '/tmp/', 'links-snapshot' ); imagepng($dst_img, $tempname); $logo["name"]='links-snapshot'; $logo["tmp_name"]=$tempname; $logo["type"]='image/png'; $logo["size"]='1'; imagedestroy($dst_img); imagedestroy($src_img); } } else { move_uploaded_file($logo["tmp_name"], ROOT . "/tmp/" . $logo["name"]); $logo["tmp_name"] = ROOT . "/tmp/" . $logo["name"]; if (!isset($logo['name']) || !isset($logo['type']) || !isset($logo['size']) || !isset($logo['tmp_name']) || !is_readable($logo['tmp_name'])) { throw new InvalidUploadError($logo, lang('error upload file')); } // if } $valid_types = array('image/jpg', 'image/jpeg', 'image/pjpeg', 'image/gif', 'image/png'); $max_width = config_option('max_logo_width', 50); $max_height = config_option('max_logo_height', 50); if (!in_array($logo['type'], $valid_types) || !($image = getimagesize($logo['tmp_name']))) { throw new InvalidUploadError($logo, lang('invalid upload type', 'JPG, GIF, PNG')); } // if $old_file = $link->getLogoPath(); DB::beginWork(); if (!$link->setLogo($logo['tmp_name'], $max_width, $max_height, true)) { DB::rollback(); flash_error(lang('error edit link logo', $e)); $this->redirectToUrl($link->getEditLogoUrl()); } // if ApplicationLogs::createLog($link, active_project(), ApplicationLogs::ACTION_EDIT); flash_success(lang('success edit logo')); DB::commit(); if (is_file($old_file)) { @unlink($old_file); } // uf } catch(Exception $e) { flash_error(lang('error edit logo', $e)); DB::rollback(); } // try $this->redirectToUrl($link->getEditLogoUrl()); } // if } // edit_logo
/** * Call back function for user link * * @param mixed $matches * @return */ function replace_link_link_callback($matches) { if (count($matches) < 2) { return null; } // if if (!logged_user()->isMemberOfOwnerCompany()) { $object = ProjectLinks::findOne(array('conditions' => array('`id` = ? AND `project_id` = ? AND `is_private` = 0 ', $matches[1], active_project()->getId()))); } else { $object = ProjectLinks::findOne(array('conditions' => array('`id` = ? AND `project_id` = ?', $matches[1], active_project()->getId()))); } // if if (!$object instanceof ProjectLink) { return '<del>' . lang('invalid reference', $matches[0]) . '</del>'; } else { return '<a href="' . externalUrl($object->getViewUrl()) . '" title="' . lang('link') . '">' . $object->getObjectName() . '</a>'; } // if }
/** * Copy project * * @param void * @return null */ function copy() { trace(__FILE__, "copy():begin"); if (!Project::canAdd(logged_user())) { flash_error(lang('no access permissions')); $this->redirectToReferer(get_url('dashboard')); } // if $this->setTemplate('copy_project'); $this->setLayout('administration'); $project_data = array_var($_POST, 'project'); tpl_assign('project_data', $project_data); // Submitted... if (is_array($project_data)) { $source = Projects::findById($project_data['source']); if (!$source instanceof Project) { flash_error(lang('project dnx')); $this->redirectTo('administration', 'projects'); } // if try { $shift_dates = isset($project_data['shift_dates']) ? $project_data['shift_dates'] == 'checked' : false; $copy_details = isset($project_data['copy_details']) ? $project_data['copy_details'] == 'checked' : false; $copy_tasks = isset($project_data['copy_tasks']) ? $project_data['copy_tasks'] == 'checked' : false; $copy_milestones = isset($project_data['copy_milestones']) ? $project_data['copy_milestones'] == 'checked' : false; $copy_messages = isset($project_data['copy_messages']) ? $project_data['copy_messages'] == 'checked' : false; $copy_links = isset($project_data['copy_links']) ? $project_data['copy_links'] == 'checked' : false; $copy_files = isset($project_data['copy_files']) ? $project_data['copy_files'] == 'checked' : false; $copy_users = isset($project_data['copy_users']) ? $project_data['copy_users'] == 'checked' : false; $copy_pages = isset($project_data['copy_pages']) ? $project_data['copy_pages'] == 'checked' : false; DB::beginWork(); $project = new Project(); $new_name = lang('projects copy new name', $source->getName()); $new_name .= date(' z H:i:s'); $project->setName($new_name); if ($copy_details) { $project->setDescription($source->getDescription()); $project->setPriority($source->getPriority()); $project->setShowDescriptionInOverview($source->getShowDescriptionInOverview()); } $project->save(); $project_id = $project->getId(); $add_seconds = 0; if (isset($project_data['add_days'])) { $add_days = 0 + trim($project_data['add_days']); $add_seconds = $add_days * 24 * 60 * 60; } $source_created_on = $source->getCreatedOn(); //var_dump($source_created_on); $milestone_map = array(0 => 0); // project milestones if ($copy_milestones) { $source_milestones = $source->getAllMilestones(); if (is_array($source_milestones)) { foreach ($source_milestones as $source_milestone) { $milestone = new ProjectMilestone(); //$milestone->copy($source_milestone); $milestone->setName($source_milestone->getName()); $milestone->setDescription($source_milestone->getDescription()); if ($shift_dates) { trace(__FILE__, "copy():shift dates"); $milestone->setDueDate(DateTimeValueLib::now()); $seconds = $source_milestone->getDueDate()->difference($source_created_on); $milestone->getDueDate()->advance($seconds); } else { $milestone->setDueDate($source_milestone->getDueDate()); } $milestone->getDueDate()->advance($add_seconds); $milestone->setIsPrivate($source_milestone->getIsPrivate()); $milestone->setAssignedToUserId($source_milestone->getAssignedToUserId()); $milestone->setAssignedToCompanyId($source_milestone->getAssignedToCompanyId()); $milestone->setProjectId($project_id); $milestone->save(); $milestone_map[$source_milestone->getId()] = $milestone->getId(); } // foreach } // if } // if // project tasks if ($copy_tasks) { $source_task_lists = $source->getAllTaskLists(); if (is_array($source_task_lists)) { foreach ($source_task_lists as $source_task_list) { $task_list = new ProjectTaskList(); //$task_list->copy($source_milestone); $task_list->setName($source_task_list->getName()); $task_list->setPriority($source_task_list->getPriority()); $task_list->setDescription($source_task_list->getDescription()); if ($copy_milestones) { $task_list->setMilestoneId($milestone_map[$source_task_list->getMilestoneId()]); } $task_list->setDueDate($source_task_list->getDueDate()); if ($task_list->getDueDate() instanceof DateTimeValue) { if ($shift_dates) { trace(__FILE__, "copy():task list shift dates"); $task_list->setDueDate(DateTimeValueLib::now()); $seconds = $source_task_list->getDueDate()->difference($source_created_on); $task_list->getDueDate()->advance($seconds); } $task_list->getDueDate()->advance($add_seconds); } $task_list->setIsPrivate($source_task_list->getIsPrivate()); $task_list->setOrder($source_task_list->getOrder()); $task_list->setProjectId($project_id); $task_list->save(); $source_tasks = $source_task_list->getTasks(); if (is_array($source_tasks)) { foreach ($source_tasks as $source_task) { $task = new ProjectTask(); $task->setOrder($source_task->getOrder()); $task->setDueDate($source_task->getDueDate()); if ($task->getDueDate() instanceof DateTimeValue) { if ($shift_dates) { trace(__FILE__, "copy():task shift dates"); $task->setDueDate(DateTimeValueLib::now()); $seconds = $source_task->getDueDate()->difference($source_created_on); $task->getDueDate()->advance($seconds); } $task->getDueDate()->advance($add_seconds); } $task->setText($source_task->getText()); $task->getAssignedToUserId($source_task->getAssignedToUserId()); $task->getAssignedToCompanyId($source_task->getAssignedToCompanyId()); $task_list->attachTask($task); } } } // foreach } // if } // if // project messages if ($copy_messages) { $source_messages = $source->getAllMessages(); if (is_array($source_messages)) { foreach ($source_messages as $source_message) { $message = new ProjectMessage(); //$message->copy($source_message); $message->setTitle($source_message->getTitle()); $message->setText($source_message->getText()); $message->setAdditionalText($source_message->getAdditionalText()); if ($copy_milestones) { $message->setMilestoneId($milestone_map[$source_message->getMilestoneId()]); } $message->setIsImportant($source_message->getIsImportant()); $message->setIsPrivate($source_message->getIsPrivate()); $message->setCommentsEnabled($source_message->getCommentsEnabled()); $message->setAnonymousCommentsEnabled($source_message->getAnonymousCommentsEnabled()); $message->setProjectId($project_id); $message->save(); } // foreach } // if } // if // project links if ($copy_links) { $source_links = ProjectLinks::getAllProjectLinks($source); if (is_array($source_links)) { foreach ($source_links as $source_link) { $link = new ProjectLink(); //$folder->copy($source_link); $link->setTitle($source_link->getTitle()); $link->setUrl($source_link->getUrl()); $link->setProjectId($project_id); $link->save(); } // foreach } // if } // if // project folders & files if ($copy_files) { $folder_map = array(0 => 0); $source_folders = $source->getFolders(); if (is_array($source_folders)) { foreach ($source_folders as $source_folder) { $folder = new ProjectFolder(); //$folder->copy($source_folder); $folder->setName($source_folder->getName()); $folder->setProjectId($project_id); $folder->save(); $folder_map[$source_folder->getId()] = $folder->getId(); } // foreach } // if $source_files = ProjectFiles::getAllFilesByProject($source); if (is_array($source_files)) { foreach ($source_files as $source_file) { $file = new ProjectFile(); $file->setProjectId($project_id); $file->setFolderId($folder_map[$source_file->getFolderId()]); $file->setFileName($source_file->getFileName()); $file->setDescription($source_file->getDescription()); $file->setIsPrivate($source_file->getIsPrivate()); $file->setIsImportant($source_file->getIsImportant()); $file->setIsLocked($source_file->getIsLocked()); $file->setIsVisible($source_file->getIsVisible()); $file->setExpirationTime($source_file->getExpirationTime()); $file->setCommentsEnabled($source_file->getCommentsEnabled()); $file->setAnonymousCommentsEnabled($source_file->getAnonymousCommentsEnabled()); $file->save(); $source_revision = $source_file->getLastRevision(); if ($source_revision instanceof ProjectFileRevision) { $revision = new ProjectFileRevision(); $revision->setFileId($file->getId()); $revision->setRevisionNumber($source_revision->getRevisionNumber()); $revision->setRepositoryId($source_revision->getRepositoryId()); $revision->setFilesize($source_revision->getFilesize()); $revision->setFilename($source_revision->getFileName()); $revision->setTypeString($source_revision->getTypeString()); $revision->setThumbFilename($source_revision->getThumbFilename()); $revision->setFileTypeId($source_revision->getFileTypeId()); $revision->setComment($source_revision->getComment()); $revision->save(); } } // foreach } // if } // if if ($copy_pages) { $source_pages = Wiki::getAllProjectPages($source); if (is_array($source_pages)) { foreach ($source_pages as $source_page) { $page = new WikiPage(); $page->setProjectId($project_id); $page->setProjectIndex($source_page->getProjectIndex()); $page->setProjectSidebar($source_page->getProjectSidebar()); if (plugin_active('tags')) { //$page->setTags($source_page->getTagNames()); } //Make a new revision of this page $revision = $page->makeRevision(); $source_revision = $source_page->getLatestRevision(); //Set attributes $revision->setName($source_revision->getName()); $revision->setContent($source_revision->getContent()); $revision->setLogMessage($source_revision->getLogMessage()); //Save the page $page->save(); } // foreach } // if } // if if ($copy_users) { $source_companies = ProjectCompanies::instance()->getCompaniesByProject($source); if (is_array($source_companies)) { foreach ($source_companies as $source_company) { $project_company = new ProjectCompany(); $project_company->setCompanyId($source_company->getId()); $project_company->setProjectId($project_id); $project_company->save(); } // foreach } $source_users = ProjectUsers::instance()->getUsersByProject($source); if (is_array($source_users)) { foreach ($source_users as $source_user) { $project_user = new ProjectUser(); $project_user->setUserId($source_user->getId()); $project_user->setProjectId($project_id); $project_user->save(); } // foreach } } /* $permissions = array_keys(PermissionManager::getPermissionsText()); $auto_assign_users = owner_company()->getAutoAssignUsers(); // We are getting the list of auto assign users. If current user is not in the list // add it. He's creating the project after all... if (is_array($auto_assign_users)) { $auto_assign_logged_user = false; foreach ($auto_assign_users as $user) { if ($user->getId() == logged_user()->getId()) { $auto_assign_logged_user = true; } } // if if (!$auto_assign_logged_user) { $auto_assign_users[] = logged_user(); } } else { $auto_assign_users[] = logged_user(); } // if foreach ($auto_assign_users as $user) { $project_user = new ProjectUser(); $project_user->setProjectId($project->getId()); $project_user->setUserId($user->getId()); if (is_array($permissions)) { foreach ($permissions as $permission) { $user = Users::findById($project_user->getUserId()); $user->setProjectPermission($project,$permission,true); } } // if $project_user->save(); } // foreach */ ApplicationLogs::createLog($project, null, ApplicationLogs::ACTION_ADD, false, true); DB::commit(); flash_success(lang('success copy project', $source->getName(), $project->getName())); $this->redirectToUrl($project->getPermissionsUrl()); } catch (Exception $e) { echo $e->getMessage(); tpl_assign('error', $e); DB::rollback(); } // try } // if (submitted) }