/**
  * Returns all Workspaces an Template belongs to
  *
  * @param $object_manager
  * @param $Template_id
  * @return array
  */
 static function getWorkspacesByTemplate($template_id, $wsCSV = null)
 {
     $all = self::findAll(array('conditions' => "`template_id` = {$template_id}" . ($wsCSV ? " AND `workspace_id` IN ({$wsCSV})" : '')));
     if (!is_array($all)) {
         return array();
     }
     $csv = "";
     foreach ($all as $w) {
         if ($csv != "") {
             $csv .= ",";
         }
         $csv .= $w->getWorkspaceId();
     }
     return Projects::findByCSVIds($csv);
 }
 /**
  * Returns all Workspaces an Object belongs to
  *
  * @param $object_manager
  * @param $object_id
  * @return array
  */
 static function getWorkspacesByObject($object_manager, $object_id, $wsCSV = null)
 {
     $all = self::findAll(array('conditions' => "`object_manager` = '{$object_manager}' AND `object_id` = {$object_id}" . ($wsCSV ? " AND `workspace_id` IN ({$wsCSV})" : '')));
     //array('`object_manager` = ? AND `object_id` = ?', $object_manager, $object_id)));
     if (!is_array($all) || count($all) == 0) {
         return array();
     }
     $csv = "";
     foreach ($all as $w) {
         if ($csv != "") {
             $csv .= ",";
         }
         $csv .= $w->getWorkspaceId();
     }
     return Projects::findByCSVIds($csv);
 }
 /**
  * Classify specific email
  *
  */
 function classify()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $email = MailContents::findById(get_id());
     if (!$email instanceof MailContent) {
         flash_error(lang('email dnx'));
         ajx_current("empty");
         return;
     }
     if ($email->getIsDeleted()) {
         flash_error(lang('email dnx deleted'));
         ajx_current("empty");
         return;
     }
     if (!$email->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     MailUtilities::parseMail($email->getContent(), $decoded, $parsedEmail, $warnings);
     $projects = logged_user()->getActiveProjects();
     tpl_assign('projects', $projects);
     $classification_data = array_var($_POST, 'classification');
     if (!is_array($classification_data)) {
         $tag_names = $email->getTagNames();
         $classification_data = array('tag' => is_array($tag_names) ? implode(', ', $tag_names) : '');
         // array
     }
     // if
     if (is_array(array_var($_POST, 'classification'))) {
         try {
             $create_task = array_var($classification_data, 'create_task') == 'checked';
             $canWriteFiles = $this->checkFileWritability($classification_data, $parsedEmail);
             if ($canWriteFiles) {
                 $project_ids = $classification_data["project_ids"];
                 $enteredWS = Projects::findByCSVIds($project_ids);
                 $validWS = array();
                 if (isset($enteredWS)) {
                     foreach ($enteredWS as $ws) {
                         if (ProjectFile::canAdd(logged_user(), $ws)) {
                             $validWS[] = $ws;
                         }
                     }
                 }
                 if (empty($validWS)) {
                     flash_error(lang('must choose at least one workspace error'));
                     ajx_current("empty");
                     return;
                 }
                 DB::beginWork();
                 $conversation = MailContents::getMailsFromConversation($email);
                 foreach ($conversation as $conv_email) {
                     $conv_email->removeFromWorkspaces(logged_user()->getWorkspacesQuery());
                     foreach ($validWS as $w) {
                         $conv_email->addToWorkspace($w);
                     }
                     $conv_email->save();
                     MailUtilities::parseMail($conv_email->getContent(), $decoded, $parsedEmail, $warnings);
                     $csv = array_var($classification_data, 'tag');
                     $conv_email->setTagsFromCSV($csv);
                     if ($conv_email->getHasAttachments()) {
                         //Classify attachments
                         $this->classifyFile($classification_data, $conv_email, $parsedEmail, $validWS, true, $csv);
                     }
                 }
                 DB::commit();
                 flash_success(lang('success classify email'));
                 if ($create_task) {
                     ajx_replace(true);
                     $this->redirectTo('task', 'add_task', array('from_email' => $email->getId(), 'replace' => 1));
                 } else {
                     ajx_current("back");
                     evt_add("reload mails panel", array());
                 }
             } else {
                 flash_error(lang("error classifying attachment cant open file"));
                 ajx_current("empty");
             }
             // If can write files
             // Error...
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
         // try
     } else {
         $classification_data["project_ids"] = $email->getWorkspaces();
     }
     tpl_assign('classification_data', $classification_data);
     tpl_assign('email', $email);
     tpl_assign('parsedEmail', $parsedEmail);
 }
 function assign_to_ws()
 {
     if (!can_manage_templates(logged_user())) {
         flash_error(lang("no access permissions"));
         ajx_current("empty");
         return;
     }
     $template_id = get_id();
     $cotemplate = COTemplates::findById($template_id);
     if (!$cotemplate instanceof COTemplate) {
         flash_error(lang("template dnx"));
         ajx_current("empty");
         return;
     }
     $selected = WorkspaceTemplates::getWorkspacesByTemplate($template_id);
     tpl_assign('workspaces', logged_user()->getWorkspaces());
     tpl_assign('selected', $selected);
     tpl_assign('cotemplate', $cotemplate);
     $checked = array_var($_POST, 'ws_ids');
     if ($checked != null) {
         try {
             DB::beginWork();
             WorkspaceTemplates::deleteByTemplate($template_id);
             $wss = Projects::findByCSVIds($checked);
             foreach ($wss as $ws) {
                 $obj = new WorkspaceTemplate();
                 $obj->setWorkspaceId($ws->getId());
                 $obj->setTemplateId($template_id);
                 $obj->setInludeSubWs(false);
                 $obj->save();
             }
             DB::commit();
             flash_success(lang('success assign workspaces'));
             ajx_current("back");
         } catch (Exception $exc) {
             DB::rollback();
             flash_error(lang('error assign workspace') . $exc->getMessage());
             ajx_current("empty");
         }
     }
 }
 function render_add_milestone()
 {
     $ws_ids = array_var($_GET, 'workspaces', '');
     $genid = array_var($_GET, 'genid', '');
     $workspaces = Projects::findByCSVIds($ws_ids);
     tpl_assign('workspaces', $workspaces);
     tpl_assign('genid', $genid);
     $this->setLayout("html");
     $this->setTemplate("add_select_milestone");
 }
Exemplo n.º 6
0
 function uploadFile($username, $password, $workspaces, $tags, $generate_rev, $filename, $description, $do_checkin, $data)
 {
     $result = array('status' => true, 'errorid' => 0, 'message' => '');
     if ($this->loginUser($username, $password)) {
         try {
             DB::beginWork();
             $file = null;
             $files = ProjectFiles::getAllByFilename($filename, logged_user()->getWorkspacesQuery());
             if (is_array($files) && count($files) > 0) {
                 if ($generate_rev) {
                     $file = ProjectFiles::findById($files[0]->getId());
                     if ($file->isCheckedOut()) {
                         if (!$file->canCheckin(logged_user())) {
                             $result['status'] = false;
                             $result['errorid'] = 1004;
                             $result['message'] = lang('no access permissions');
                         }
                         $file->setCheckedOutById(0);
                     } else {
                         // Check for edit permissions
                         if (!$file->canEdit(logged_user())) {
                             $result['status'] = false;
                             $result['errorid'] = 1004;
                             $result['message'] = lang('no access permissions');
                         }
                     }
                 }
             }
             if ($result['status']) {
                 $enteredWS = Projects::findByCSVIds($workspaces);
                 $validWS = array();
                 foreach ($enteredWS as $ws) {
                     if (ProjectFile::canAdd(logged_user(), $ws)) {
                         $validWS[] = $ws;
                     }
                 }
                 if (count($validWS) == 0) {
                     $result['status'] = false;
                     $result['errorid'] = 1005;
                     $result['message'] = 'Invalid workspaces given. Check access permissions.';
                 } else {
                     $make_revision_comment = $file != null;
                     if ($file == null) {
                         $file = new ProjectFile();
                         $file->setFilename($filename);
                         $file->setIsVisible(true);
                         $file->setIsPrivate(false);
                         $file->setIsImportant(false);
                         $file->setCommentsEnabled(true);
                         $file->setAnonymousCommentsEnabled(false);
                         $file->setCreatedOn(new DateTimeValue(time()));
                         $file->setDescription($description);
                     }
                     $file_dt['name'] = $file->getFilename();
                     $file_dt['size'] = strlen($data);
                     $file_dt['tmp_name'] = ROOT . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . rand();
                     $extension = trim(get_file_extension($file->getFilename()));
                     $file_dt['type'] = Mime_Types::instance()->get_type($extension);
                     if (!trim($file_dt['type'])) {
                         $file_dt['type'] = 'text/html';
                     }
                     $handle = fopen($file_dt['tmp_name'], "w");
                     fwrite($handle, $data, $file_dt['size']);
                     fclose($handle);
                     $file->save();
                     $revision = $file->handleUploadedFile($file_dt, true, $make_revision_comment ? $description : '');
                     $file->setTagsFromCSV($tags);
                     foreach ($validWS as $w) {
                         $file->addToWorkspace($w);
                     }
                     foreach ($validWS as $w) {
                         ApplicationLogs::createLog($file, $w, ApplicationLogs::ACTION_ADD);
                     }
                     DB::commit();
                     $result['message'] = 'd' . str_pad($file->getId(), 3, '0', STR_PAD_LEFT) . 'r' . $file->getRevisionNumber();
                     if (!$do_checkin) {
                         $this->checkoutFile($username, $password, $file->getId());
                     }
                 }
             }
         } catch (Exception $e) {
             DB::rollback();
             $result['message'] = $e->getMessage();
             $result['errorid'] = 1003;
             $result['status'] = false;
             // If we uploaded the file remove it from repository
             if (isset($revision) && $revision instanceof ProjectFileRevision && FileRepository::isInRepository($revision->getRepositoryId())) {
                 FileRepository::deleteFile($revision->getRepositoryId());
             }
         }
     } else {
         $result['status'] = false;
         $result['errorid'] = 1002;
         $result['message'] = lang('invalid login data');
     }
     return $this->result_to_xml($result, 'result');
 }
 function allowed_users_view_events()
 {
     $comp_array = array();
     $actual_user_id = isset($_GET['user']) ? $_GET['user'] : logged_user()->getId();
     $wspace_id = isset($_GET['ws_id']) ? $_GET['ws_id'] : 0;
     $ws = Projects::findByCSVIds($wspace_id);
     $evid = array_var($_GET, 'evid');
     $companies = Companies::findAll();
     $i = 0;
     foreach ($companies as $comp) {
         $users = $comp->getUsersOnWorkspaces($ws);
         if (is_array($users)) {
             foreach ($users as $k => $user) {
                 // removing event creator from notification list
                 $keep = false;
                 foreach ($ws as $w) {
                     if (can_read_type($user, $w, 'ProjectEvents')) {
                         $keep = true;
                     }
                 }
                 if (!$keep) {
                     unset($users[$k]);
                 }
             }
             if (count($users) > 0) {
                 $comp_data = array('id' => $i++, 'object_id' => $comp->getId(), 'name' => $comp->getName(), 'logo_url' => $comp->getLogoUrl(), 'users' => array());
                 foreach ($users as $user) {
                     $comp_data['users'][] = array('id' => $user->getId(), 'name' => $user->getDisplayName(), 'avatar_url' => $user->getAvatarUrl(), 'invited' => $evid == 0 ? $user->getId() == $actual_user_id : EventInvitations::findOne(array('conditions' => "`event_id` = {$evid} and `user_id` = " . $user->getId())) != null, 'mail' => $user->getEmail());
                 }
                 $comp_array[] = $comp_data;
             }
         }
     }
     $object = array("totalCount" => count($comp_array), "start" => 0, "companies" => array());
     $object['companies'] = $comp_array;
     ajx_extra_data($object);
     ajx_current("empty");
 }
 function add_to_workspaces($object, $force_ws = true)
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $object->removeFromWorkspaces(logged_user()->getWorkspacesQuery());
     $ids = array_var($_POST, "ws_ids", "");
     $enteredWS = Projects::findByCSVIds($ids);
     $validWS = array();
     foreach ($enteredWS as $ws) {
         if ($object->canAdd(logged_user(), $ws)) {
             $validWS[] = $ws;
         }
     }
     if (empty($validWS) && $force_ws) {
         throw new Exception(lang('must choose at least one workspace error'));
     }
     foreach ($validWS as $w) {
         $object->addToWorkspace($w);
     }
     return $validWS;
 }
 /**
  * Update company permissions
  *
  * @param void
  * @return null
  */
 function update_permissions()
 {
     if (!logged_user()->isAdministrator(owner_company())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $company = Companies::findById(get_id());
     if (!$company instanceof Company) {
         flash_error(lang('company dnx'));
         ajx_current("empty");
         return;
     }
     // if
     if ($company->isOwner()) {
         flash_error(lang('error owner company has all permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $projects = Projects::getAll(Projects::ORDER_BY_NAME);
     if (!is_array($projects) || !count($projects)) {
         flash_error(lang('no projects in db'));
         ajx_current("empty");
         return;
     }
     // if
     tpl_assign('projects', $projects);
     tpl_assign('company', $company);
     if (array_var($_POST, 'submitted') == 'submitted') {
         $counter = 0;
         $logged_user = logged_user();
         // reuse...
         ProjectCompanies::delete('company_id = ' . $company->getId());
         $wsids = array_var($_POST, 'ws_ids', '');
         $selected = Projects::findByCSVIds($wsids);
         $counter = 0;
         foreach ($selected as $ws) {
             $pc = new ProjectCompany();
             $pc->setCompanyId($company->getId());
             $pc->setProjectId($ws->getId());
             $pc->save();
             $counter++;
         }
         flash_success(lang('success update company permissions', $counter));
         ajx_current("back");
     }
     // if
 }