1: <?php
2: 3: 4: 5:
6: class projectHandler extends reportHandler {
7:
8: public $viewhandler;
9: public $managerhandler;
10: public $customerhandler;
11: public $memberhandler;
12: public $taskhandler;
13: public $notificationhandler;
14: public $grouphandler;
15: public $dbhandler;
16:
17: protected $application_name = "project";
18:
19: private $member_objlist = array();
20: private $person_objlist = array();
21: private $service_objlist = array();
22: private $equipment_objlist = array();
23: private $user_uid_list = array();
24: private $obj_rmlist = array();
25: private $status_count = array();
26: private $priority_count = array();
27: private $component_count = array();
28: private $task_type_list = array();
29: private $task_type_list_enabled = array();
30: private $task_status_list_enabled = array();
31:
32: public function __construct($appid = null,$schema = 'public'){
33: $this->ident = 'project';
34: $this->setAppColumnDefinitions();
35: $this->view_edit_handlers = array('project' => 'project','project_task' => 'tasks');
36:
37: $this->appid = $appid;
38: $this->member_objlist = array();
39: $this->customerhandler = new customerHandler();
40: $this->managerhandler = new userHandler();
41: $this->taskhandler = new projectTaskHandler(null,null,null,null,null,null);
42: $this->confighandler = new projectConfigHandler();
43: $this->grouphandler = new groupHandler();
44: $this->db = null;
45:
46: $this->instance = $this;
47: $this->createObjInstance(array("notificationhandler","notificationHandler",null));
48: $this->createObjInstance(array("viewhandler","projectViewHandler",$this->instance));
49: $this->createObjInstance(array("sideviewhandler","appSideViewHandler",$this->instance));
50: $this->initialize();
51:
52: $this->setPermEnforce(true);
53: $this->application_nr = PROJECT_APP;
54: $this->viewhandler->setHeaderIdent("project",null);
55:
56: parent::__construct($appid,false);
57: }
58:
59: public function setDataSource(&$db){
60: $column_types = $this->getColumnTypesAll();
61: $this->dbhandler = new projectDbHandler($db,$column_types,$this->column_method_pointers);
62: $this->customerhandler->setDataSource($db);
63: $this->managerhandler->setDataSource($db);
64: $this->taskhandler->setDataSource($db);
65: $this->grouphandler->setDataSource($db);
66:
67: $this->db = &$db;
68: }
69:
70: public function &getDataSource(){
71: return $this->dbhandler;
72: }
73:
74: public function destructDbInstances(){
75: unset($this->dbhandler);
76: unset($this->db);
77: $this->customerhandler->destructDbInstances();
78: $this->managerhandler->destructDbInstances();
79: $this->taskhandler->destructDbInstances();
80: $this->grouphandler->destructDbInstances();
81: foreach($this->member_objlist as $mobj){
82: if ( is_object($mobj) ) $mobj->destructDbInstances();
83: }
84: }
85:
86: public function &getDataObject($ident){
87: switch($ident){
88: case "customer":
89: return $this->customerhandler;
90: break;
91:
92: case "task":
93: return $this->taskhandler;
94: break;
95:
96: case "customer":
97: return $this->customerhandler;
98: break;
99:
100: default:
101: return $this->instance;
102: break;
103: }
104: }
105:
106: public function systemUpdate(){
107: if ($this->getProjectId()){
108: $this->setProjecTaskStatusList();
109: $this->setProjecTaskPriorityList();
110: $this->setProjecTaskTypeList();
111: }
112: }
113:
114: public function initialize(){
115: foreach (array_keys($this->column_types[1]) as $key){
116: if (isset($this->column_types[1][$key]["value"])){
117: $this->column_types[1][$key]["value"] = null;
118: }
119: }
120:
121: $this->setAppTargetId(null);
122: $this->task_type_list = array();
123: $this->task_type_list_enabled = array();
124: $task_status_list_enabled = array();
125: $this->member_objlist = array();
126: $this->person_objlist = array();
127: $this->service_objlist = array();
128: $this->equipment_objlist = array();
129: $this->user_uid_list = array();
130: $this->appl_access_objlist = array();
131:
132: $this->customerhandler->initialize();
133: $this->managerhandler->initialize();
134:
135: $this->status_count = array();
136: $this->priority_count = array();
137: $this->component_count = null;
138: $this->obj_rmlist = array();
139: $this->cleanPermissions();
140:
141: $this->addNewObject($this->getUserid(),"member");
142:
143:
144: $this->acl_list_arr = array();
145: $this->viewhandler->setHeaderIdent("project",null);
146: }
147:
148: public function initializeById($id){
149: if (intval($id) == 0)
150: $id = $this->dbhandler->getProjectIdByKey($id);
151: if (!intval($id))
152: if ($this->getUserId() == VISITOR_ID)
153: throw new Exception("invalid_project_id_login_required");
154: else
155: throw new Exception("invalid_project_id");
156:
157: $this->setColumnMethodTypes($id);
158: if ($this->verifyApplicationPermission($id,$this->getUserId(),'default','READ') == false) {
159: $this->initialize();
160: throw new Exception("invalid permissions or data not found");
161: }
162:
163: $this->setColumnMethodTypes($id);
164:
165: $this->appl_access_objlist = array();
166: $this->customerhandler->initializeById($this->dbhandler->getProjectCustomerId($id));
167: $this->managerhandler->initializeById($this->getProjectManager());
168:
169: $this->initializeEnvironment();
170: $this->initApplAccessData($id);
171:
172: $this->setProjectUserList();
173: $this->setLastModifiedDate($this->dbhandler->getLastTransactionData($this->getProjectId(),true));
174: $this->setAppTargetId($id);
175: $this->viewhandler->setHeaderIdent("project","{$this->getProjectName()}");
176: }
177:
178: public function setProjecTaskStatusList(){
179: $this->task_status_list_enabled = $this->dbhandler->getProjectTaskStatusesEnabled(intval($this->getProjectId()));
180: }
181:
182: public function setProjectTaskStatusDefault($id,$project_id){
183: $this->dbhandler->setProjectTaskStatusDefault(intval($id),intval($project_id));
184: $this->dbhandler->updateSystemData();
185: }
186:
187: public function getProjectTaskStatusDefaultId($project_id){
188: return $this->dbhandler->getProjectTaskStatusDefaultId($project_id);
189: }
190:
191: public function setProjecTaskPriorityList(){
192: $this->task_priority_list_enabled = $this->dbhandler->getProjectTaskPrioritiesEnabled(intval($this->getProjectId()));
193: }
194:
195: public function setProjecTaskTypeList(){
196: $this->task_type_list = $this->dbhandler->getProjectTaskTypes(intval($this->getProjectId()));
197: $this->task_type_list_enabled = $this->dbhandler->getProjectTaskTypesEnabled(intval($this->getProjectId()));
198: }
199:
200: public function setProjectTaskPriorityDefault($id,$project_id){
201: $this->dbhandler->setProjectTaskPriorityDefault(intval($id),intval($project_id));
202: $this->dbhandler->updateSystemData();
203: }
204:
205: public function setProjectTaskTypeDefault($id,$project_id){
206: $this->dbhandler->setProjectTaskTypeDefault(intval($id),intval($project_id));
207: $this->dbhandler->updateSystemData();
208: }
209:
210: public function getProjectTaskTypeDefaultId($project_id){
211: return $this->dbhandler->getProjectTaskTypeDefaultId($project_id);
212: }
213:
214: public function getProjecTaskTypeList(){
215: return $this->task_type_list;
216: }
217:
218: public function getProjecTaskTypeListEnabled(){
219: return $this->task_type_list_enabled;
220: }
221:
222: public function getProjecTaskStatusListEnabled(){
223: return $this->task_status_list_enabled;
224: }
225:
226: public function getProjecTaskPriorityListEnabled(){
227: return $this->task_priority_list_enabled;
228: }
229:
230: public function projecTaskStatusEnable($project_id,
231: $task_status_id,
232: $task_status_enabled){
233: if ($task_status_enabled == 'true'){
234: $this->dbhandler->projectTaskStatusEnable($project_id,$task_status_id);
235: }else{
236: $this->dbhandler->projectTaskStatusDisable($project_id,$task_status_id);
237: }
238: $this->dbhandler->updateSystemData();
239: }
240:
241: public function projecTaskPriorityEnable($project_id,
242: $task_priority_id,
243: $task_priority_enabled){
244: if ($task_priority_enabled == 'true'){
245: $this->dbhandler->projectTaskPriorityEnable($project_id,$task_priority_id);
246: }else{
247: $this->dbhandler->projectTaskPriorityDisable($project_id,$task_priority_id);
248: }
249: $this->dbhandler->updateSystemData();
250: }
251:
252: public function projecTaskTypeEnable($project_id,
253: $task_type_id,
254: $task_type_enabled){
255:
256: if ($task_type_enabled == 'true'){
257: $this->dbhandler->projectTaskTypeEnable($project_id,$task_type_id);
258: }else{
259: $this->dbhandler->projectTaskTypeDisable($project_id,$task_type_id);
260: }
261: $this->dbhandler->updateSystemData();
262: }
263:
264:
265: public function verifyProjectRegistrationEmail($username){
266: list ($name,$domain) = explode('@',$username);
267: $name = "$name$domain";
268: $pattern = array('.','@','-');
269: $dbuser = str_replace($pattern,'_',$name);
270:
271: $schema_usernames = $this->dbhandler->getProjectSchemaUsernames();
272: foreach(array_keys($schema_usernames) as $key){
273: if (strtolower($schema_usernames[$key][0]) == strtolower($dbuser))
274: throw new Exception('user_exists');
275: }
276: }
277:
278: public function verifyProjectRegistrationKey($project_key){
279: $schema_keys = $this->dbhandler->getProjectSchemaKeys();
280: foreach(array_keys($schema_keys) as $key){
281: if (strtolower($schema_keys[$key][0]) == strtolower($project_key))
282: throw new Exception('project_key_exists');
283: }
284: }
285:
286: public function generateProjectKey($project_name){
287: $project_name = trim($project_name);
288: $keys = str_split(str_replace(" ", "", $project_name));
289: $length = strlen($project_name)-1;
290: $project_key = "{$keys[0]}{$keys[1]}{$keys[2]}";
291: try {
292: $this->verifyProjectRegistrationKey($project_key);
293: }catch(Exception $e){
294: $project_key = $this->generateRandomProjectKey($keys,$length);
295: }
296: return strtoupper($project_key);
297: }
298:
299: private function generateRandomProjectKey($keylist,$length){
300: $project_key = null;
301: $i = 0;
302: while(1){
303: $i++;
304: if ($i > 10) break;
305: try {
306: $project_key = "{$keylist[0]}".$keylist[rand(1,$length)].$keylist[rand(1,$length)];
307: $this->verifyProjectRegistrationKey($project_key);
308: }catch(Exception $e){
309: continue;
310: }
311: break;
312: }
313: return $project_key;
314: }
315:
316: protected function getGuestAccess($project_id = null){
317: return $project_id == null ? $this->getProjectGuestAccess() : $this->dbhandler->getProjectGuestAccess($project_id);
318: }
319:
320: public function setProjectGuestAccess($guest_access){
321: $this->dbhandler->setProjectGuestAccess($this->getProjectId(),$guest_access);
322: }
323:
324: public function getProjectUserList(){
325: $user_list = array("unassigned" => 0);
326: return array_merge($user_list,$this->user_uid_list);
327: }
328:
329: public function setProjectTaskStatusCounts($options_arr = null){
330: $sprint_id = isset($options_arr['sprint_id']) && intval($options_arr['sprint_id']) ? intval($options_arr['sprint_id']) : null;
331: $backlog_id = isset($options_arr['backlog_id']) && intval($options_arr['backlog_id']) ? intval($options_arr['backlog_id']) : null;
332: if ($sprint_id){
333: $this->status_count = $this->dbhandler->getScrumSprintTaskStatusCount($sprint_id);
334: }elseif ($backlog_id){
335: $this->status_count = $this->dbhandler->getScrumBacklogTaskStatusCount($backlog_id);
336: }elseif (intval($this->getProjectId()) > 0){
337: $this->status_count = $this->dbhandler->getProjectTaskStatusCount($this->getProjectId(),$options_arr);
338: }
339: }
340:
341: public function setProjectTaskPriorityCounts($options_arr = null){
342: $sprint_id = isset($options_arr['sprint_id']) && intval($options_arr['sprint_id']) ? intval($options_arr['sprint_id']) : null;
343: $backlog_id = isset($options_arr['backlog_id']) && intval($options_arr['backlog_id']) ? intval($options_arr['backlog_id']) : null;
344: if ($sprint_id){
345: $this->priority_count = $this->dbhandler->getScrumSprintTaskPriorityCount($sprint_id);
346: }elseif ($backlog_id){
347: $this->priority_count = $this->dbhandler->getScrumBacklogTaskPriorityCount($backlog_id);
348: }elseif (intval($this->getProjectId()) > 0){
349: $this->priority_count = $this->dbhandler->getProjectTaskPriorityCount($this->getProjectId(),$options_arr);
350: }
351: }
352:
353: public function setProjectTaskTypeCounts($options_arr = null){
354: $sprint_id = isset($options_arr['sprint_id']) && intval($options_arr['sprint_id']) ? intval($options_arr['sprint_id']) : null;
355: $backlog_id = isset($options_arr['backlog_id']) && intval($options_arr['backlog_id']) ? intval($options_arr['backlog_id']) : null;
356: if ($sprint_id){
357: $this->type_count = $this->dbhandler->getScrumSprintTaskTypeCount($sprint_id);
358: }elseif ($backlog_id){
359: $this->type_count = $this->dbhandler->getScrumBacklogTaskTypeCount($backlog_id);
360: }elseif (intval($this->getProjectId()) > 0){
361: $this->type_count = $this->dbhandler->getProjectTaskTypeCount($this->getProjectId(),$options_arr);
362: }
363: }
364:
365: public function getProjectTaskStatusCounts($options_arr = array(),$reload = false){
366: if ($reload) $this->setProjectTaskStatusCounts($options_arr);
367: return $this->status_count;
368: }
369:
370: public function getProjectTaskStatusCount($status){
371: if (isset($this->status_count[$status])) return $this->status_count[$status];
372: return false;
373: }
374:
375: public function getProjectTaskPriorityCounts($options_arr = array(),$reload = false){
376: if ($reload) $this->setProjectTaskPriorityCounts($options_arr);
377: return $this->priority_count;
378: }
379:
380: public function getProjectTaskPriorityCount($status){
381: if (isset($this->priority_count[$status])) return $this->priority_count[$status];
382: return false;
383: }
384:
385: public function getProjectTaskTypeCounts($options_arr = array(),$reload = false){
386: if ($reload) $this->setProjectTaskTypeCounts($options_arr);
387: return $this->type_count;
388: }
389:
390: public function getProjectTaskTypeCount($status){
391: if (isset($this->type_count[$status])) return $this->type_count[$status];
392: return false;
393: }
394:
395: public function getProjectTaskComponentCount($reload = false){
396: if ($reload || count($this->component_count) == 0)
397: $this->setProjectTaskComponentCount();
398:
399: if (isset($this->component_count))
400: return $this->component_count;
401:
402: return false;
403: }
404:
405: public function setProjectTaskComponentCount(){
406: if (intval($this->getProjectId()) > 0){
407: $this->component_count = array();
408: $this->component_count = $this->dbhandler->getProjectTaskComponentCount($this->getProjectId());
409: }
410: }
411:
412: public function getProjectTaskDefaultComponent(){
413: $i = 0;
414: $component_list = $this->getProjectTaskComponentCount();
415: $component_name = null;
416: $component_version = null;
417: $component_id = null;
418: $version_id = null;
419:
420:
421: while(1){
422: if (!isset($component_list[$i][0])) break;
423: $component_name = $component_list[$i][3];
424: $component_version = $component_list[$i][4];
425: $component_id = $component_list[$i][0];
426: $version_id = $component_list[$i][1];
427:
428: if ($component_list[$i][6] == 1) break;
429: $i++;
430: }
431: return array($component_name,$component_version,$component_id,$version_id);
432: }
433:
434: public function syncStorage(){
435: if ($this->getProjectId() > 0)
436: $this->syncStorageUpdate();
437: else
438: $this->syncStorageInsert();
439: }
440:
441: public function getStatusElementName(){
442: return "project_status";
443: }
444:
445: protected function syncStorageUpdate(){
446:
447: try {
448: $this->dbhandler->db->transactionStart();
449: $this->dbhandler->updateData($this->getProjectId(),$this->column_types);
450:
451: if ($this->datehandler->verifyDateValue($this->getProjectPlanStartDate()))
452: $this->dbhandler->updateProjectPlannedStartDate($this->getProjectId(),$this->getProjectPlanStartDate());
453:
454: if ($this->datehandler->verifyDateValue($this->getProjectPlanEndDate()))
455: $this->dbhandler->updateProjectPlannedEndDate($this->getProjectId(),$this->getProjectPlanEndDate());
456:
457: if ($this->datehandler->verifyDateValue($this->getProjectStartDate()))
458: $this->dbhandler->updateProjectStartDate($this->getProjectId(),$this->getProjectStartDate());
459:
460: if ($this->datehandler->verifyDateValue($this->getProjectEndDate()))
461: $this->dbhandler->updateProjectEndDate($this->getProjectId(),$this->getProjectEndDate());
462:
463: $this->setProjectTaskStatusCounts();
464:
465: $this->viewhandler->setHeaderIdent("project","{$this->getProjectName()}");
466: }catch (Exception $e){
467: $this->dbhandler->db->transactionRollback();
468: throw new Exception($e->getMessage());
469: }
470: $this->dbhandler->db->transactionEnd();
471: }
472: protected function syncStorageInsert(){
473: global $STATUS_LIST;
474:
475: $pkey = $this->getProjectKey();
476:
477: $this->setCustomerId(1);
478: if ($this->dbhandler->getProjectNameById($this->getProjectName())) throw new Exception($this->translator->translate('project_name_exists'));
479: if ($this->dbhandler->getProjectKeyById($this->getProjectKey())) throw new Exception($this->translator->translate('project_key_exists'));
480: if (!$this->stringCheck($pkey)) throw new Exception($this->translator->translate('project_key_not_defined'));
481:
482: try {
483:
484: if (isset($STATUS_LIST['PROJECT']))
485: $this->setProjectStatus($STATUS_LIST['PROJECT']['CREATED'][0]);
486: $this->setProjectId($this->dbhandler->insertData($this->column_types));
487:
488: if ($this->datehandler->verifyDateValue($this->getProjectPlanStartDate()))
489: $this->dbhandler->updateProjectPlannedStartDate($this->getProjectId(),$this->getProjectPlanStartDate());
490:
491: if ($this->datehandler->verifyDateValue($this->getProjectPlanEndDate()))
492: $this->dbhandler->updateProjectPlannedEndDate($this->getProjectId(),$this->getProjectPlanEndDate());
493:
494: if ($this->datehandler->verifyDateValue($this->getProjectStartDate()))
495: $this->dbhandler->updateProjectStartDate($this->getProjectId(),$this->getProjectStartDate());
496:
497: if ($this->datehandler->verifyDateValue($this->getProjectEndDate()))
498: $this->dbhandler->updateProjectEndDate($this->getProjectId(),$this->getProjectEndDate());
499:
500: $this->taskhandler->componenthandler->setDefaultComponent($this->getProjectId());
501:
502: $this->setDefaultTaskStatuses();
503: $this->setDefaultTaskTypes();
504: $this->setDefaultTaskPriorities();
505:
506: $this->initializeEnvironment();
507:
508:
509: $access = array("write"=>true,"read"=>true,"modify"=>true,"create"=>true);
510: $this->setAccessPermissions(PROJECT_APP,$this->getProjectId(),$this->getUserId(),"member","default",$access);
511:
512:
513: $this->updateApplAccessData($this->getProjectId());
514:
515: $this->setLastModifiedDate($this->dbhandler->getLastTransactionData($this->getProjectId(),true));
516: $this->viewhandler->setHeaderIdent("project","{$this->getProjectName()}");
517: }catch (Exception $e){
518: $this->dbhandler->db->transactionRollback();
519: error_log($e->getMessage());
520: throw new Exception($e->getMessage());
521: }
522: $this->dbhandler->db->transactionEnd();
523: }
524:
525: public function setProjectMilestone($id,$name,$project_id,$start_date,$end_date,$estimated_start_date,$estimated_end_date,$description,$achievements,$deviations){
526: try {
527:
528: if (intval($id) == 0 && $this->dbhandler->verifyMilestoneExistence($name,$project_id) != null)
529: throw new Exception('milestone_exists');
530:
531: $start_date = $this->datehandler->verifyDateValue($start_date) == false ? $this->datehandler->getDateNullValue() : trim($start_date);
532: $end_date = $this->datehandler->verifyDateValue($end_date) == false ? $this->datehandler->getDateNullValue() : trim($end_date);
533: $estimated_start_date = $this->datehandler->verifyDateValue($estimated_start_date) == false ? $this->datehandler->getDateNullValue() : trim($estimated_start_date);
534: $estimated_end_date = $this->datehandler->verifyDateValue($estimated_end_date) == false ? $this->datehandler->getDateNullValue() : trim($estimated_end_date);
535:
536:
537: if (intval($id) > 0 )
538: return $this->dbhandler->updateProjectMilestone($id,$name,$project_id,$start_date,$end_date,$estimated_start_date,$estimated_end_date, $description,$achievements,$deviations);
539: else
540: return $this->dbhandler->insertProjectMilestone($name,$project_id,$start_date,$end_date,$estimated_start_date,$estimated_end_date, $description,$achievements,$deviations);
541:
542: }catch (Exception $e){
543: throw new Exception($e->getMessage());
544: }
545: }
546:
547: public function getProjectMilestones(){
548: return $this->dbhandler->getProjectMilestones($this->getProjectId());
549: }
550:
551: public function deleteProjectMilestone($milestone_id){
552: $this->dbhandler->deleteProjectMilesone($milestone_id);
553: }
554:
555: public function syncStorageRemove(){
556: if (is_numeric($this->getProjectId()) == false) throw new Exception('project_not_selected');
557:
558: try {
559: $this->dbhandler->db->transactionStart();
560: $this->dbhandler->deleteProjectData($this->getProjectId());
561: $this->initialize();
562: }catch (Exception $e){
563: $this->dbhandler->db->transactionRollback();
564: throw new Exception($e->getMessage());
565: }
566: $this->dbhandler->db->transactionEnd();
567: }
568:
569: public function updateObjectData($object_type){
570: try {
571: if (isset($object_type))
572: for ($i = 0 ; $i < $this->getObjCount($object_type) ; $i++){
573: $objref = $this->getObjectByIndx($i,$object_type);
574: if (is_object($objref)){
575:
576: switch($object_type){
577: case "person":
578: if ( is_numeric($objref->getPersonId()) && $objref->getPersonId() > 0 ) {
579:
580: }else{
581: $objref->syncStorageInsert(false);
582: $this->dbhandler->insertProjectPerson($this->getProjectId(),$objref->getPersonId());
583: }
584: break;
585:
586: case "equipment":
587: if ( $this->dbhandler->checkEquipmentId($this->getProjectId(),$objref->getEquipmentId()) == false)
588: $this->dbhandler->insertProjectEquipment($this->getProjectId(),$objref->getEquipmentId());
589:
590: if ($this->datehandler->verifyDateValue($objref->getEquipmentStartDate()))
591: $this->dbhandler->setEquipmentStartDate($this->getProjectId(),$objref->getEquipmentId(),$objref->getEquipmentStartDate());
592:
593: if ($this->datehandler->verifyDateValue($objref->getEquipmentEndDate()))
594: $this->dbhandler->setEquipmentEndDate($this->getProjectId(),$objref->getEquipmentId(),$objref->getEquipmentEndDate());
595: break;
596:
597: case "service":
598: if ( $this->dbhandler->checkServiceId($this->getProjectId(),$objref->getServiceId()) == false)
599: $this->dbhandler->insertProjectService($this->getProjectId(),$objref->getServiceId());
600:
601: if ($this->datehandler->verifyDateValue($objref->getServiceStartDate()))
602: $this->dbhandler->setServiceStartDate($this->getProjectId(),$objref->getServiceId(),$objref->getServiceStartDate());
603:
604: if ($this->datehandler->verifyDateValue($objref->getServiceEndDate()))
605: $this->dbhandler->setServiceEndDate($this->getProjectId(),$objref->getServiceId(),$objref->getServiceEndDate());
606: break;
607: }
608:
609: if (count($this->obj_rmlist) > 0){
610: foreach ($this->obj_rmlist as $indx => $data_arr){
611: foreach ($data_arr as $key => $val){
612: switch($key){
613: case "equipment":
614: $this->dbhandler->removeProjectEquipment($this->getProjectId(),intval($val));
615: break;
616:
617: case "service":
618: $this->dbhandler->removeProjectService($this->getProjectId(),intval($val));
619: break;
620: }
621: }
622: }
623: }
624: }
625: }
626:
627: }catch (Exception $e){
628: throw new Exception($e->getMessage());
629: }
630: return true;
631: }
632:
633: public function getUserProjects($permission = 'READ'){
634: $projects_arr = array();
635: $data_arr = $this->dbhandler->searchProjectData(null,null,null,null,null);
636: if (!is_array($data_arr)) return array(null,null);
637:
638: foreach ($data_arr as $data){
639:
640: $guest_access = isset($data[4]) ? intval($data[4]) : null;
641: $project_id = isset($data[5]) ? intval($data[5]) : null;
642: $app_perm = $this->verifyApplicationPermission($project_id,$this->getUserId(), "default",$permission);
643: if ($app_perm || intval($guest_access) ) {
644: array_push($projects_arr,$data);
645: }
646: }
647: return array($projects_arr);
648: }
649:
650: public function getItemObjectList(){
651: }
652:
653: public function getEquipmentObjectList(){
654: return $this->equipment_objlist;
655: }
656:
657: public function removeObjectItem($id = null,$type = null){
658: switch ($type){
659: case "equipment":
660: $keyval = array_search($id,$this->equipment_objlist);
661: if (isset($keyval)){
662: array_push($this->obj_rmlist,array("equipment" => $id));
663: unset($this->equipment_objlist[$keyval]);
664: }
665: break;
666:
667: case "person":
668: $keyval = array_search($id,$this->person_objlist);
669: if (isset($keyval)){
670: array_push($this->obj_rmlist,array("person" => $id));
671: unset($this->person_objlist[$keyval]);
672: }
673: break;
674:
675:
676: case "service":
677: $keyval = array_search($id,$this->service_objlist);
678: if (isset($keyval)){
679: array_push($this->obj_rmlist,array("service" => $id));
680: unset($this->service_objlist[$keyval]);
681: }
682: break;
683: }
684: }
685:
686: public function getObjCount($type = null){
687: switch($type){
688: case "member":
689: return count($this->member_objlist);
690: break;
691:
692: case "person":
693: return count($this->person_objlist);
694: break;
695:
696:
697: case "service":
698: return count($this->service_objlist);
699: break;
700:
701: case "equipment":
702: return count($this->equipment_objlist);
703: break;
704: }
705: }
706:
707: public function setObjectList($id,$type = null,$details = false){
708: $resultset_arr = array();
709: switch($type){
710: case "person":
711: $resultset_arr = $this->dbhandler->getPersonHeader($id);
712: if (!is_array($resultset_arr)) return false;
713: for ($i = 0 ; $i < count($resultset_arr) ; $i++){
714: list ($id,$role,$desc,$person_id) = $resultset_arr[$i];
715: $personobj = new projectPersonHandler($id,$role,$desc,$person_id);
716: $this->pushPerson($memberobj);
717: }
718: break;
719:
720: case "service":
721: $resultset_arr = $this->dbhandler->getServiceHeader($id);
722: if (!is_array($resultset_arr)) return false;
723: for ($i = 0 ; $i < count($resultset_arr) ; $i++){
724: list ($id,$name,$desc,$customer_id,$start_date,$end_date) = $resultset_arr[$i];
725: $memberobj = new projectContractorHandler($id,$name,$desc,$customer_id,$start_date,$end_date);
726: $this->pushService($memberobj);
727: }
728: break;
729:
730: case "equipment":
731: $resultset_arr = $this->dbhandler->getEquipmentHeader($id);
732: if (!is_array($resultset_arr)) return false;
733: for ($i = 0 ; $i < count($resultset_arr) ; $i++){
734: list ($id,$name,$model,$manufacturer,$build_date,$desc,$start_date,$end_date) = $resultset_arr[$i];
735: $eqobj = new projectEquipmentHandler($id,$name,$model,$manufacturer,$build_date,$desc,$start_date,$end_date);
736: $this->pushEquipment($eqobj);
737: }
738: break;
739: }
740: }
741:
742: public function addNewObject($newid,$type = null){
743: global $STATUS_LIST;
744: switch($type){
745:
746: case "person":
747: foreach($this->person_objlist as $mobj){
748: if (is_object($mobj) && $mobj->getPersonId() == $newid) throw new Exception($this->translator->translate('person_exists'));
749: }
750: $newobj = new projectPersonHandler(null,null,null,$newid);
751: $newobj->setDataSource($this->db);
752: $newobj->initializePersonData($newid);
753: $this->pushPerson($newobj);
754: break;
755:
756:
757: case "equipment":
758: foreach($this->equipment_objlist as $mobj){
759: if (is_object($mobj) && $mobj->getEquipmentId() == $newid) throw new Exception($this->translator->translate('equipment_exists'));
760: }
761: $newobj = new projectEquipmentHandler($newid,null,null,null,null,null,null,null);
762: $newobj->setDataSource($this->db);
763: $newobj->initializeEquipmentData($newid);
764: $this->pushEquipment($newobj);
765: break;
766:
767: case "service":
768: foreach($this->service_objlist as $mobj)
769: if (is_object($mobj) && $mobj->getServiceId() == $newid) throw new Exception($this->translator->translate('service_exists'));
770: $newobj = new projectContractorHandler(null,null,null,$newid,null,null);
771: $newobj->setDataSource($this->db);
772: $newobj->initializeContractorData($newid);
773: $newobj->initializeCustomerData($newid);
774: $this->pushService($newobj);
775: break;
776: }
777: }
778:
779: public function &getObjectByIndx($indx,$type,$autocreate = true){
780: switch($type){
781: case "person":
782: if (isset($this->person_objlist[$indx]) && is_object($this->person_objlist[$indx]) )
783: return $this->person_objlist[$indx];
784: break;
785:
786: case "equipment":
787: if (!isset($this->equipment_objlist[$indx]) && $autocreate == true ||
788: isset($this->equipment_objlist[$indx]) && !is_object($this->equipment_objlist[$indx]) && $autocreate == true)
789: $this->pushEquipment(new projectEquipmentHandler(null,null,null,null));
790:
791: if (isset($this->equipment_objlist[$indx]) && is_object($this->equipment_objlist[$indx]) ) return $this->equipment_objlist[$indx];
792: break;
793:
794: case "service":
795: if (!isset($this->service_objlist[$indx]) && $autocreate == true ||
796: isset($this->service_objlist[$indx]) && !is_object($this->service_objlist[$indx]) && $autocreate == true)
797: $this->pushService(new projectServiceHandler(null,null,null,null));
798:
799: if (isset($this->service_objlist[$indx]) && is_object($this->service_objlist[$indx]) ) return $this->service_objlist[$indx];
800: break;
801: }
802: }
803:
804: public function removeService($memberid){
805: $keyval = array_search($memberid,$this->service_objlist);
806: if (isset($keyval)){
807: unset($this->service_objlist[$keyval]);
808: }
809: }
810:
811: public function getPersonList(){
812: return $this->person_objlist;
813: }
814:
815: public function pushPerson($personobj){
816: if ($this->keycheck($this->person_objlist,$personobj) != "FALSE" && is_object($personobj)) {
817: array_push($this->person_objlist,$personobj);
818: }
819: }
820:
821: public function pushEquipment($memberobj){
822: if ($this->keycheck($this->equipment_objlist,$memberobj) != "FALSE" && is_object($memberobj)) {
823: array_push($this->equipment_objlist,$memberobj);
824: }
825: }
826:
827: public function pushService($obj){
828: if ($this->keycheck($this->service_objlist,$obj) != "FALSE" && is_object($obj)) {
829: array_push($this->service_objlist,$obj);
830: }
831: }
832:
833: public function getServiceObjectList(){
834: return $this->service_objlist;
835: }
836:
837:
838: public function getSalesInvoices(){
839: if (is_numeric($this->getProjectId())) return $this->dbhandler->getSalesInvoices($this->getProjectId());
840: return array();
841: }
842:
843: public function getInvoicesTotalSum(){
844: return 0;
845: if (is_numeric($this->getProjectId())) return $this->invoice_dbhandler->getProjectPaymentSumTotalData($this->getProjectId());
846: return null;
847: }
848:
849: public function getPurchaseInvoices(){
850: if (is_numeric($this->getProjectId())) return $this->dbhandler->getPurchaseInvoices($this->getProjectId());
851: return array();
852: }
853:
854: public function getPurchaseInvoicesTotalSum(){
855: return 0;
856: if (is_numeric($this->getProjectId())) return $this->purchase_dbhandler->getProjectBillingSumTotalData($this->getProjectId());
857: return null;
858: }
859:
860: public function getProjectIdByKey($key){
861: return $this->dbhandler->getProjectIdByKey($key);
862: }
863:
864: public function getProjectManagerName(){
865: return $this->managerhandler->getUserName();
866: }
867:
868: public function setProjectManagerData($d){
869: if (!intval($d)) return false;
870: $this->setProjectManager($d);
871: $this->managerhandler->initializeById($this->getProjectManager());
872:
873: }
874:
875: public function setEquipmentStartDate($val,$indx){
876: $obj = $this->getObjectByIndx($indx,'equipment');
877: if (is_object($obj)) $obj->setEquipmentStartDate($val);
878: }
879:
880: public function setEquipmentEndDate($val,$indx){
881: $obj = $this->getObjectByIndx($indx,'equipment');
882: if (is_object($obj)) $obj->setEquipmentEndDate($val);
883: }
884:
885: public function setServiceStartDate($val,$indx){
886: $obj = $this->getObjectByIndx($indx,'service');
887: if (is_object($obj)) $obj->setServiceStartDate($val);
888: }
889:
890: public function setServiceEndDate($val,$indx){
891: $obj = $this->getObjectByIndx($indx,'service');
892: if (is_object($obj)) $obj->setServiceEndDate($val);
893: }
894:
895: public function searchProjectData($status = null,$category = null,$search_value = null,$offset = null,$limit = null){
896: return $this->dbhandler->searchProjectData($category,
897: $status,
898: $search_value,
899: $offset,
900: $limit);
901: }
902:
903: public function getGroupUserList($id){
904: $this->grouphandler->initializeById($id);
905: return $this->grouphandler->getGroupUserlist();
906: }
907:
908:
909: public function getStatusAppList(){
910: global $STATUS_LIST;
911: return $STATUS_LIST['PROJECT'];
912: }
913:
914: public function getSelectedStatus(){
915: global $STATUS_LIST;
916: if ($this->getProjectId()) {
917: if ($this->getProjectStatus() > 0)
918: return $this->getProjectStatus();
919: return $STATUS_LIST['PROJECT']['CREATED'][0];
920: }
921: return null;
922: }
923:
924: public function setInvitationRequest($email,$token){
925: $this->dbhandler->setInvitationRequest($this->getSchemaName(),$this->getProjectKey(),$email,$token);
926: }
927:
928: public function registerProjectMember($params_arr){
929: $token = $params_arr['reg_project_invite_token'];
930: $password = $params_arr['reg_project_password'];
931:
932: try {
933:
934: $reqdata = $this->dbhandler->getRegistrationMemberdata($token);
935: $regdbhandler = new projectRegistrationDbHandler($this->db);
936: if ($reqdata != null){
937: list ($token,$user_id,$key,$project_key,$schema_id) = $reqdata;
938: $regdbhandler->insertRegistrationMemberInformation($user_id,$schema_id,md5($password));
939: }
940: $regdbhandler->deleteRegistrationMemberdata($token);
941: unset($regdbhandler);
942: }catch (Exception $e){
943: error_log("error: {$e->getMessage()}");
944: unset($regdbhandler);
945: $this->dbhandler->db->transactionRollback();
946: throw new Exception($e->getMessage());
947: }
948: }
949:
950:
951: public function getColumnAssociationTypes(){
952: return $this->getProjecTaskTypeList();
953:
954: }
955:
956: private function initializeEnvironment(){
957: $this->setProjectTaskStatusCounts();
958: $this->setProjectTaskPriorityCounts(null);
959: $this->setProjectTaskComponentCount();
960: $this->setProjecTaskStatusList();
961: $this->setProjecTaskPriorityList();
962: $this->setProjecTaskTypeList();
963: }
964:
965: private function keycheck ($member_arr,$id){
966: return false;
967: }
968:
969: private function setProjectUserList(){
970: $i = 0;
971: while(1){
972: $accobj = $this->getAppAccessObjByIndx($i);
973: if ( !is_object($accobj) ) break;
974: switch($accobj->getAccessPermTargetType()){
975: case "member":
976: $this->user_uid_list[$accobj->getIdent()] = $accobj->getAccessPermTargetId();
977:
978: break;
979: case "group":
980: $this->grouphandler->initializebyId($accobj->getIdent());
981: $group_uid_list = $this->grouphandler->getGroupUserlist();
982: if (is_array($group_uid_list))
983: foreach(array_keys($group_uid_list) as $key){
984: list ($uid,$ident) = array($group_uid_list[$key][0],$group_uid_list[$key][1]);
985: if (!isset($this->user_uid_list[$ident]))
986: $this->user_uid_list[$ident] = $uid;
987: }
988: break;
989: }
990: $i++;
991: }
992: $this->dbhandler->updateSystemData();
993: }
994:
995: private function setDefaultTaskPriorities(){
996: global $STATUS_LIST;
997: $project_id = $this->getProjectId();
998: if (isset($STATUS_LIST['TASK_PRIORITY']))
999: foreach (array_keys($STATUS_LIST['TASK_PRIORITY']) as $key){
1000:
1001: $status_id = $STATUS_LIST['TASK_PRIORITY'][$key][0];
1002: $this->dbhandler->projectTaskPriorityEnable($project_id,$status_id);
1003: }
1004: }
1005:
1006: private function setDefaultTaskStatuses(){
1007: global $STATUS_LIST;
1008: $project_id = $this->getProjectId();
1009: if (isset($STATUS_LIST['PROJECT_TASK']))
1010: foreach (array_keys($STATUS_LIST['PROJECT_TASK']) as $key){
1011: $status_id = $STATUS_LIST['PROJECT_TASK'][$key][0];
1012: $this->dbhandler->projectTaskStatusEnable($project_id,$status_id);
1013: }
1014: }
1015:
1016: private function setDefaultTaskTypes(){
1017:
1018: $type_list_arr = $this->dbhandler->getProjectTaskTypes(0);
1019: $project_id = $this->getProjectId();
1020: if (is_array($type_list_arr))
1021: foreach (array_keys($type_list_arr) as $key){
1022: $task_type_id = $type_list_arr[$key][0];
1023: $task_name = $type_list_arr[$key][1];
1024: $this->dbhandler->projectTaskTypeEnable($project_id,$task_type_id);
1025: if ($task_name == 'task')
1026: $this->setProjectTaskTypeDefault($task_type_id,$project_id);
1027: }
1028: }
1029:
1030: public function autoCompleteSprints(){
1031: $this->dbhandler->autoCompleteSprints($this->getProjectId(),$this->datehandler->getCurrentDate());
1032: }
1033:
1034: public function createScrumSprint($name){
1035: $this->dbhandler->createScrumSprint($name,$this->getProjectId());
1036: }
1037:
1038: public function getScrumBacklog(){
1039: return $this->dbhandler->getScrumBacklog($this->getProjectId());
1040: }
1041:
1042: public function getScrumSprints(){
1043: return $this->dbhandler->getScrumSprints($this->getProjectId());
1044: }
1045:
1046: public function getScrumSprintTasks(){
1047: return $this->dbhandler->getScrumSprintTasks($this->getProjectId());
1048: }
1049:
1050: public function updateSprintAutoComplete($sprint_id,$value){
1051: $this->dbhandler->updateSprintAutoComplete($sprint_id,$value);
1052: }
1053:
1054: public function addScrumSprintTask($task_key,$sprint_id){
1055: return $this->dbhandler->addScrumSprintTask($this->taskhandler->getTaskIdByKey($task_key),$sprint_id);
1056: }
1057:
1058: public function updateScrumSprintDateStart($sprint_id,$value){
1059: $this->dbhandler->updateScrumSprintDateStart($sprint_id,$value);
1060: }
1061:
1062: public function updateScrumSprintDateEnd($sprint_id,$value){
1063: $this->dbhandler->updateScrumSprintDateEnd($sprint_id,$value);
1064: }
1065:
1066: public function getSprintStoryPoints($sprint_id){
1067: return $this->dbhandler->getSPrintStoryPoints($sprint_id);
1068: }
1069:
1070: public function getSprintStoryPointsByStatus($sprint_id,$statuslist){
1071: return $this->dbhandler->getSPrintStoryPointsByStatus($sprint_id,$statuslist);
1072: }
1073:
1074: public function addScrumBacklogTask($backlog_id,$task_key){
1075: $backlog_id = $backlog_id == null ? $this->getScrumBoardId() : $backlog_id;
1076: return $this->dbhandler->addScrumBacklogTask($this->taskhandler->getTaskIdByKey($task_key),$backlog_id);
1077: }
1078:
1079: public function getScrumActiveSprint($board_id){
1080: return $this->dbhandler->getScrumActiveSprint($board_id);
1081: }
1082:
1083: public function getScrumSprintStatus($sprint_id){
1084: return $this->dbhandler->getScrumSprintStatus($sprint_id);
1085: }
1086:
1087: public function setScrumSprintStatus($sprint_id,$status){
1088: return $this->dbhandler->setScrumSprintStatus($sprint_id,$status);
1089: }
1090:
1091: public function getScrumBoardId($name = 'default'){
1092: return $this->dbhandler->getScrumBoardId($this->getProjectId(),$name);
1093: }
1094:
1095: public function setScrumBacklogSprintId($backlog_id,$task_key,$active_sprint_id){
1096: $this->dbhandler->setScrumBacklogSprintId($backlog_id,$this->taskhandler->getTaskIdByKey($task_key),$active_sprint_id);
1097: }
1098:
1099: public function createTaskBoardView($name){
1100: return $this->dbhandler->createTaskBoardView($name,$this->getProjectId());
1101: }
1102:
1103: public function createProjectRelease($name,$board_id,$rel_date,$task_list_arr){
1104: $this->dbhandler->createTaskBoardRelease($name, $rel_date,$board_id,$task_list_arr);
1105: }
1106:
1107: public function getProjectReleases($board_id){
1108: return $this->dbhandler->getProjectReleases($board_id);
1109: }
1110:
1111: private function getTaskBoardViewId($name){
1112: return $this->dbhandler->getTaskBoardViewId($name,$this->getProjectId());
1113: }
1114:
1115: }
1116:
1117: ?>
1118: