Example #1
0
 /**
  * test testgetActivitiesWithName() method.
  */
 public function testGetActivitiesWithName()
 {
     // Verify that invalid project ids throw exceptions
     try {
         ProjectActivity::getActivitiesWithName("", "Test");
         $this->fail("Exception not thrown");
     } catch (ProjectActivityException $e) {
         // Expected
     }
     // Verify that invalid project ids throw exceptions
     try {
         ProjectActivity::getActivitiesWithName("xafd", "Test");
         $this->fail("Exception not thrown");
     } catch (ProjectActivityException $e) {
         // Expected
     }
     // Verify that invalid project ids throw exceptions
     try {
         ProjectActivity::getActivitiesWithName(null, "Test");
         $this->fail("Exception not thrown");
     } catch (ProjectActivityException $e) {
         // Expected
     }
     // Test that activity name is escaped to avoid sql injection.
     // If not, following will throw an error.
     ProjectActivity::getActivitiesWithName(1, "' WHERE xkaf in (SELECT * from xaf)");
     // non existent name (with empty table)
     $list = ProjectActivity::getActivitiesWithName(1, "Test activity");
     $this->assertEquals(0, count($list));
     // create some activities
     $actList = $this->_getTestActivities();
     $this->_createActivites($actList);
     // non existent name
     $list = ProjectActivity::getActivitiesWithName(1, "Test activity 2");
     $this->assertEquals(0, count($list));
     // valid name
     $list = ProjectActivity::getActivitiesWithName(1, "test 1");
     $this->assertEquals(1, count($list));
     $obj = $list[0];
     $this->assertEquals($actList[$obj->getId()], $obj);
     // verify that deleted activities are not included by default
     $list = ProjectActivity::getActivitiesWithName(1, "test 3");
     $this->assertEquals(0, count($list));
     // include deleted activities
     $list = ProjectActivity::getActivitiesWithName(1, "test 3", true);
     $this->assertEquals(1, count($list));
     $obj = $list[0];
     $this->assertEquals($actList[$obj->getId()], $obj);
     // multiple matches
     mysql_query("UPDATE ohrm_project_activity SET name = 'test name' where project_id = 1");
     $list = ProjectActivity::getActivitiesWithName(1, "test name");
     $this->assertEquals(2, count($list));
     $list = ProjectActivity::getActivitiesWithName(1, "test name", true);
     $this->assertEquals(3, count($list));
 }
 function addData($index, $object, $noRedirect = false)
 {
     try {
         switch ($index) {
             case 'EST':
                 $empstat = new EmploymentStatus();
                 $empstat = $object;
                 $res = $empstat->addEmpStat();
                 break;
             case 'JEM':
                 $jobtit_empstat = new JobTitEmpStat();
                 $jobtit_empstat = $object;
                 $res = $jobtit_empstat->addJobTitEmpStat();
                 break;
             case 'JOB':
                 $jobtit = new JobTitle();
                 $jobtit = $object;
                 $res = $jobtit->addJobTitles();
                 $id = $jobtit->getJobId();
                 break;
             case 'SPC':
                 $jobSpec = $object;
                 try {
                     $res = $jobSpec->save();
                 } catch (JobSpecException $e) {
                     $res = false;
                 }
                 break;
             case 'CST':
                 $compstruct = new CompStruct();
                 $compstruct = $object;
                 $res = $compstruct->addCompStruct();
                 break;
             case 'BNK':
                 $bankinfo = new BankInfo();
                 $bankinfo = $object;
                 $res = $bankinfo->addBankInfo();
                 break;
             case 'TAX':
                 $taxinfo = new TaxInfo();
                 $taxinfo = $object;
                 $res = $taxinfo->addTaxInfo();
                 break;
             case 'CCB':
                 $cashben = new CashBen();
                 $cashben = $object;
                 $res = $cashben->addCashBenefits();
                 break;
             case 'COS':
                 $cost = new CostCenter();
                 $cost = $object;
                 $res = $cost->addCostCenter();
                 break;
             case 'COU':
                 $country = new CountryInfo();
                 $country = $object;
                 $res = $country->addCountryInfo();
                 break;
             case 'CUR':
                 $currency = new CurrencyTypes();
                 $currency = $object;
                 $res = $currency->addCurrencyTypes();
                 break;
             case 'DWT':
                 $dwinfo = new DwellingType();
                 $dwinfo = $object;
                 $res = $dwinfo->addDwellingType();
                 break;
             case 'ELE':
                 $eleinfo = new ElectorateInfo();
                 $eleinfo = $object;
                 $res = $eleinfo->addElectorateInfo();
                 break;
             case 'EMC':
                 $empcatinfo = new EmployeeCat();
                 $empcatinfo = $object;
                 $res = $empcatinfo->addEmployeeCat();
                 break;
             case 'EMG':
                 $empgrpinfo = new EmployeeGroup();
                 $empgrpinfo = $object;
                 $res = $empgrpinfo->addEmployeeGroup();
                 break;
             case 'ETY':
                 $emptype = new EmployeeType();
                 $emptype = $object;
                 $res = $emptype->addEmployeeType();
                 break;
             case 'EXC':
                 $exccat = new ExtraCurrActCat();
                 $exccat = $object;
                 $res = $exccat->addExtraCurrActCat();
                 break;
             case 'DEF':
                 $hicode = new HierarchyDefInfo();
                 $hicode = $object;
                 $res = $hicode->addHierarchyDefInfo();
                 break;
             case 'JDC':
                 $jdcat = new JDCategory();
                 $jdcat = $object;
                 $res = $jdcat->addJDCategory();
                 break;
             case 'LOC':
                 $loc = new models_eimadmin_Location();
                 $loc = $object;
                 $res = $loc->addLocation();
                 break;
             case 'TCP':
                 $tcp = new CompProperty();
                 $tcp = $object;
                 $res = $tcp->addProperty();
                 break;
             case 'MEM':
                 $memtype = new MembershipType();
                 $memtype = $object;
                 $res = $memtype->addMembershipType();
                 break;
             case 'NAT':
                 $natinfo = new NationalityInfo();
                 $natinfo = $object;
                 $res = $natinfo->addNationalityInfo();
                 break;
             case 'NCB':
                 $noncashben = new NonCashBen();
                 $noncashben = $object;
                 $res = $noncashben->addNonCashBenefits();
                 break;
             case 'QLF':
                 $qualtype = new QualificationType();
                 $qualtype = $object;
                 $res = $qualtype->addQualificationType();
                 break;
             case 'RTM':
                 $rattype = new RatingTypes();
                 $rattype = $object;
                 $id = $rattype->getRatingId();
                 $res = $rattype->addRatingTypes();
                 break;
             case 'RTE':
                 $rouinfo = new RouteInfo();
                 $rouinfo = $object;
                 $res = $rouinfo->addRouteInfo();
                 break;
             case 'SGR':
                 $salgread = new SalaryGrades();
                 $salgread = $object;
                 try {
                     $salgread->addSalaryGrades();
                     $res = true;
                 } catch (SalaryGradesException $e) {
                     if ($e->getCode() == SalaryGradesException::DUPLICATE_SALARY_GRADE) {
                         $showMsg = "DUPLICATE_NAME_FAILURE";
                     } elseif ($e->getCode() == SalaryGradesException::UNKNOWN_EXCEPTION) {
                         $showMsg = "ADD_FAILURE";
                     }
                     $res = false;
                 }
                 $id = $salgread->getSalGrdId();
                 break;
             case 'SKI':
                 $skill = new Skills();
                 $skill = $object;
                 $res = $skill->addSkills();
                 break;
             case 'ETH':
                 $ethnicrace = new EthnicRace();
                 $ethnicrace = $object;
                 $res = $ethnicrace->addEthnicRace();
                 break;
             case 'EXA':
                 $extcainfo = new ExtraCurActInfo();
                 $extcainfo = $object;
                 $res = $extcainfo->addExtraCurActInfo();
                 break;
             case 'MME':
                 $membinfo = new MembershipInfo();
                 $membinfo = $object;
                 $res = $membinfo->addMembershipInfo();
                 break;
             case 'JDK':
                 $jdkr = new JDKra();
                 $jdkr = $object;
                 $res = $jdkr->addJDKra();
                 break;
             case 'LAN':
                 $laninfo = new LanguageInfo();
                 $laninfo = $object;
                 $res = $laninfo->addLanguageInfo();
                 break;
             case 'RLG':
                 $relinfo = new ReligionInfo();
                 $relinfo = $object;
                 $res = $relinfo->addReligionInfo();
                 break;
             case 'SAT':
                 $satinfo = new SatutoryInfo();
                 $satinfo = $object;
                 $res = $satinfo->addSatutoryInfo();
                 break;
             case 'UNI':
                 $unitype = new UniformType();
                 $unitype = $object;
                 $res = $unitype->addUniformType();
                 break;
             case 'EXA':
                 $excurac = new ExtraCurActInfo();
                 $excurac = $object;
                 $res = $excurac->addExtraCurActInfo();
                 break;
             case 'EDU':
                 $edu = new Education();
                 $edu = $object;
                 $res = $edu->addEducation();
                 break;
             case 'SSK':
                 $subsk = new SubSkillInfo();
                 $subsk = $object;
                 $res = $subsk->addSubSkillInfo();
                 break;
             case 'JDT':
                 $jdt = new JDType();
                 $jdt = $object;
                 $res = $jdt->addJDType();
                 break;
             case 'SBJ':
                 $subin = new SubjectInfo();
                 $subin = $object;
                 $res = $subin->addSubjectInfo();
                 break;
             case 'BCH':
                 $brch = new Branches();
                 $brch = $object;
                 $res = $brch->addBranches();
                 break;
             case 'CHI':
                 $cmphier = new CompHierachy();
                 $cmphier = $object;
                 $res = $cmphier->addCompHierachy();
                 break;
             case 'CTT':
                 $corptit = new CorpTitle();
                 $corptit = $object;
                 $res = $corptit->addCorpTitles();
                 break;
             case 'DSG':
                 $desig = new Designations();
                 $desig = $object;
                 $res = $desig->addDesignations();
                 break;
             case 'DIS':
                 $disinfo = new DistrictInfo();
                 $disinfo = $object;
                 $res = $disinfo->addDistrictInfo();
                 break;
             case 'EEC':
                 $eeojobcat = new EEOJobCat();
                 $eeojobcat = $object;
                 $res = $eeojobcat->addEEOJobCat();
                 break;
             case 'LIC':
                 $licenses = new Licenses();
                 $licenses = $object;
                 $res = $licenses->addLicenses();
                 break;
             case 'CUS':
                 $customer = new Customer();
                 $customer = $object;
                 $res = $customer->addCustomer();
                 $id = $customer->getCustomerId();
                 break;
             case 'CTM':
                 $customField = $object;
                 try {
                     $customField->addCustomField();
                     $res = true;
                 } catch (CustomFieldsException $e) {
                     $res = false;
                 }
                 $id = $customField->getFieldNumber();
                 break;
             case 'CEX':
                 $customExport = $object;
                 try {
                     $customExport->save();
                     $res = true;
                 } catch (CustomExportException $e) {
                     if ($e->getCode() == CustomExportException::DUPLICATE_EXPORT_NAME) {
                         $showMsg = "DUPLICATE_NAME_FAILURE";
                     }
                     $res = false;
                 }
                 $id = $customExport->getId();
                 break;
             case 'CIM':
                 $customImport = $object;
                 try {
                     $customImport->save();
                     $res = true;
                 } catch (CustomImportException $e) {
                     if ($e->getCode() == CustomImportException::DUPLICATE_IMPORT_NAME) {
                         $showMsg = "DUPLICATE_NAME_FAILURE";
                     }
                     if ($e->getCode() == CustomImportException::COMPULSARY_FIELDS_NOT_ASSIGNED) {
                         $showMsg = "COMPULSARY_FIELDS_NOT_ASSIGNED_FAILURE";
                     }
                     $res = false;
                 }
                 $id = $customImport->getId();
                 break;
             case 'IMP':
                 $authorizeObj = new authorize($_SESSION['empID'], $_SESSION['isAdmin']);
                 if ($authorizeObj->isAdmin()) {
                     $csvImport = $object;
                     try {
                         $res = $csvImport->handleUpload();
                     } catch (CSVImportException $e) {
                         if ($e->getCode() == CSVImportException::IMPORT_DATA_NOT_RECEIVED) {
                             $showMsg = "IMPORT_FAILURE";
                         }
                         $res = false;
                     } catch (CSVSplitterException $e) {
                         if ($e->getCode() == CSVSplitterException::DIRECTORY_NOT_WRITABLE || $e->getCode() == CSVSplitterException::FILES_NOT_WRITABLE) {
                             $showMsg = "IMPORT_TEMPDIR_NOT_WRITABLE_FAILURE";
                             $res = false;
                         }
                         if ($e->getCode() == CSVSplitterException::SOURCE_FILE_NOT_FOUND || $e->getCode() == CSVSplitterException::SOURCE_FILE_NOT_READABLE) {
                             $showMsg = "IMPORT_FILE_PERMISSION_ERROR";
                             $res = false;
                         }
                         if ($e->getCode() == CSVSplitterException::SOURCE_FILE_EMPTY) {
                             $showMsg = "IMPORT_FILE_EMPTY_ERROR";
                             $res = false;
                         }
                     }
                 }
                 break;
             case 'PAD':
                 $projectAdmin = $object;
                 $id = $projectAdmin->getProjectId();
                 $gw = new ProjectAdminGateway();
                 $res = $gw->addAdmin($id, $projectAdmin->getEmpNumber());
                 break;
             case 'PRJ':
                 $project = $object;
                 $res = $project->addProject();
                 $id = $project->getProjectId();
                 break;
             case 'PAC':
                 $projectActivity = $object;
                 $id = $projectActivity->getProjectId();
                 $name = $projectActivity->getName();
                 $res = true;
                 $activities = ProjectActivity::getActivitiesWithName($id, $name);
                 if (empty($activities)) {
                     try {
                         $projectActivity->save();
                     } catch (ProjectActivityException $e) {
                         $res = false;
                     }
                 }
                 break;
             case 'USR':
                 $users = new Users();
                 $users = $object;
                 $res = $users->addUsers();
                 break;
             case 'USG':
                 $usergroups = new UserGroups();
                 $usergroups = $object;
                 $res = $usergroups->addUserGroups();
                 $id = $usergroups->getUserGroupID();
                 break;
         }
     } catch (Exception $e) {
         $res = false;
         if ($e->getCode() == 1) {
             $showMsg = "DUPLICATE_NAME_FAILURE";
         }
     }
     // Checking whether the $message Value returned is 1 or 0
     if ($res) {
         switch ($index) {
             case 'IMP':
                 $this->reDirect($_GET, $res);
                 break;
             case 'CEX':
                 // Go to CSV heading Define page
                 header("Location: ./CentralController.php?uniqcode=CHD&id={$id}");
                 break;
             case 'SGR':
                 $backtype = isset($_POST['backtype']) ? $_POST['backtype'] : '';
                 $refcapturemode = isset($_POST['refcapturemode']) ? $_POST['refcapturemode'] : '';
                 $refid = isset($_POST['refid']) ? $_POST['refid'] : '';
                 header("Location: ./CentralController.php?uniqcode=SGR&id={$id}&capturemode=updatemode&backtype={$backtype}&refcapturemode={$refcapturemode}&refid={$refid}");
                 break;
             case 'RTM':
                 header("Location: ./CentralController.php?uniqcode=RTG&id={$id}");
                 break;
             case 'CST':
                 header("Location: ./CentralController.php?uniqcode=CST&VIEW=MAIN");
                 break;
             case 'USG':
                 header("Location: ./CentralController.php?uniqcode=UGR&id={$id}");
                 break;
             case 'JEM':
                 break;
             case 'JOB':
                 header("Location: ./CentralController.php?uniqcode=JOB&id={$id}&capturemode=updatemode");
                 break;
             case 'PAD':
                 // Project admin page. Fall through to PRJ case below.
             // Project admin page. Fall through to PRJ case below.
             case 'PRJ':
                 header("Location: ./CentralController.php?message=ADD_SUCCESS&uniqcode=PRJ&id={$id}&capturemode=updatemode");
                 break;
             case 'PAC':
                 header("Location: ./CentralController.php?message=ADD_SUCCESS&uniqcode=PAC&projectId={$id}");
                 break;
             case 'EST':
             case 'LOC':
                 if ($noRedirect) {
                     break;
                 }
             case 'TCP':
                 if ($noRedirect) {
                     break;
                 }
             case 'CUR':
                 if ($noRedirect) {
                     break;
                 }
             default:
                 $showMsg = "ADD_SUCCESS";
                 //If $message is 1 setting up the
                 $uniqcode = $index;
                 $esp = isset($_GET['isAdmin']) ? '&isAdmin=' . $_GET['isAdmin'] : '';
                 header("Location: ./CentralController.php?message={$showMsg}&uniqcode={$uniqcode}&VIEW=MAIN{$esp}");
         }
     } else {
         $esp = isset($_GET['isAdmin']) ? '&isAdmin=' . $_GET['isAdmin'] : '';
         if (!isset($showMsg) || empty($showMsg)) {
             $showMsg = "DUP_USERS_FAILURE";
         }
         $uniqcode = $index;
         header("Location: ./CentralController.php?msg={$showMsg}&capturemode=addmode&uniqcode={$uniqcode}{$esp}");
     }
 }