public function import($AppUI) { $output = ''; $company_id = (int) w2PgetParam($_POST, 'company_id', 0); if ($company_id == 0) { if (isset($_POST['new_company'])) { $companyName = w2PgetParam($_POST, 'new_company', 'New Company'); $company = new CCompany(); $company->company_name = $companyName; $company->company_owner = $AppUI->user_id; $AppUI->version_major <= 1 && $AppUI->version_minor <= 1 ? $company->store() : $company->store($AppUI); $company_id = $company->company_id; $output .= $AppUI->_('createcomp') . $companyName . '<br>'; echo $output; } else { $error = $AppUI->_('emptycomp'); return $error; } } $result = $this->_processProject($AppUI, $company_id, $_POST); if (is_array($result)) { $AppUI->setMsg($result, UI_MSG_ERROR); $AppUI->redirect('m=importers'); } $this->project_id = $result; $q = new DBQuery(); // Users Setup if (isset($_POST['users']) && is_array($_POST['users']) && $_POST['nouserimport'] != "true") { foreach ($_POST['users'] as $ruid => $r) { $q->clear(); if (!empty($r['user_username'])) { $result = $this->_processContact($AppUI, $r['user_username'], $company_id); if (is_array($result)) { $AppUI->setMsg($result, UI_MSG_ERROR); $AppUI->redirect('m=importers'); } $contact_id = $result; //TODO: Replace with the regular create users functionality $q->addInsert('user_username', $r['user_username']); $q->addInsert('user_contact', $contact_id); $q->addTable('users'); $q->exec(); $insert_id = db_insert_id(); $r['user_id'] = $insert_id; } else { $r['user_id'] = $r['user_userselect']; } if (!empty($r['user_id'])) { $resources[$ruid] = $r; } } } // Tasks Setup foreach ($_POST['tasks'] as $k => $task) { $result = $this->_processTask($AppUI, $this->project_id, $task); if (is_array($result)) { $AppUI->setMsg($result, UI_MSG_ERROR); $AppUI->redirect('m=importers'); } $task_id = $result; // Task Parenthood $outline[$task['OUTLINENUMBER']] = $task_id; $q->clear(); if (!strpos($task['OUTLINENUMBER'], '.')) { $q->addUpdate('task_parent', $task_id); $q->addWhere('task_id = ' . $task_id); $q->addTable('tasks'); } else { $parent_string = substr($task['OUTLINENUMBER'], 0, strrpos($task['OUTLINENUMBER'], '.')); $parent_outline = isset($outline[$parent_string]) ? $outline[$parent_string] : $task_id; $q->addUpdate('task_parent', $parent_outline); $q->addWhere('task_id = ' . $task_id); $q->addTable('tasks'); } $q->exec(); $task['task_id'] = $task_id; $tasks[$task['UID']] = $task; // Resources (Workers) if (count($task['resources']) > 0) { $sql = "DELETE FROM user_tasks WHERE task_id = {$task_id}"; db_exec($sql); $resourceArray = array(); foreach ($task['resources'] as $uk => $user) { $alloc = $task['resources_alloc'][$uk]; if ($alloc > 0 && $resources[$user]['user_id'] > 0) { $q->clear(); if (!in_array($resources[$user]['user_id'], $resourceArray)) { $q->addInsert('user_id', $resources[$user]['user_id']); $q->addInsert('task_id', $task_id); $q->addInsert('perc_assignment', $alloc); $q->addTable('user_tasks'); $q->exec(); } $resourceArray[] = $resources[$user]['user_id']; } } } } //dependencies have to be handled alone after all tasks have been saved since the //predecessor (ms project term) task might come later and the associated task id //is not yet available. foreach ($tasks as $k => $task) { // Task Dependencies if (isset($task['dependencies']) && is_array($task['dependencies'])) { $sql = "DELETE FROM task_dependencies WHERE dependencies_task_id = {$task_id}"; db_exec($sql); $dependencyArray = array(); foreach ($task['dependencies'] as $task_uid) { if ($task_uid > 0 && $tasks[$task_uid]['task_id'] > 0) { $q->clear(); if (!in_array($tasks[$task_uid]['task_id'], $dependencyArray)) { $q->addInsert('dependencies_task_id', $task['task_id']); $q->addInsert('dependencies_req_task_id', $tasks[$task_uid]['task_id']); $q->addTable('task_dependencies'); $q->exec(); } $dependencyTestArray[] = $tasks[$task_uid]['task_id']; } } } } $this->_deDynamicLeafNodes($this->project_id); addHistory('projects', $this->project_id, 'add', $projectName, $this->project_id); return $output; }
if (!$obj->bind($_POST)) { $AppUI->setMsg($obj->getError(), UI_MSG_ERROR); $AppUI->redirect(); } require_once $AppUI->getSystemClass('CustomFields'); // prepare (and translate) the module name ready for the suffix $AppUI->setMsg('Company'); if ($del) { if (!$obj->canDelete($msg)) { $AppUI->setMsg($msg, UI_MSG_ERROR); $AppUI->redirect(); } if ($msg = $obj->delete()) { $AppUI->setMsg($msg, UI_MSG_ERROR); $AppUI->redirect(); } else { $AppUI->setMsg('deleted', UI_MSG_ALERT, true); $AppUI->redirect('m=companies'); } } else { if ($msg = $obj->store()) { $AppUI->setMsg($msg, UI_MSG_ERROR); } else { $custom_fields = new CustomFields($m, 'addedit', $obj->company_id, 'edit'); $custom_fields->bind($_POST); $sql = $custom_fields->store($obj->company_id); // Store Custom Fields $AppUI->setMsg(@$_POST['company_id'] ? 'updated' : 'added', UI_MSG_OK, true); } $AppUI->redirect(); }
<?php /* $Id$ $URL$ */ if (!defined('W2P_BASE_DIR')) { die('You should not access this file directly.'); } $del = (int) w2PgetParam($_POST, 'del', 0); $obj = new CCompany(); if (!$obj->bind($_POST)) { $AppUI->setMsg($obj->getError(), UI_MSG_ERROR); $AppUI->redirect(); } $action = $del ? 'deleted' : 'stored'; $result = $del ? $obj->delete($AppUI) : $obj->store($AppUI); if (is_array($result)) { $AppUI->setMsg($result, UI_MSG_ERROR, true); $AppUI->holdObject($obj); $AppUI->redirect('m=companies&a=addedit'); } if ($result) { $AppUI->setMsg('Company ' . $action, UI_MSG_OK, true); $AppUI->redirect('m=companies'); } else { $AppUI->redirect('m=public&a=access_denied'); }