function test_getName()
 {
     //Arrange
     $name = "Biology";
     $address = "346 Stupid Avenue";
     $test_department = new Department($name, $address);
     //Act
     $result = $test_department->getName();
     //Assert
     $this->assertEquals($name, $result);
 }
Exemplo n.º 2
0
    $stmt = $pdo->prepare($query);
    $stmt->execute(array(':assigned_id' => $_REQUEST['assigned_id'], ':id' => $_REQUEST['id']));
    // Update entries in dept_reviewer
    $query = "UPDATE {$GLOBALS['CONFIG']['db_prefix']}dept_reviewer SET dept_id = :assigned_id WHERE dept_id = :id";
    $stmt = $pdo->prepare($query);
    $stmt->execute(array(':assigned_id' => $_REQUEST['assigned_id'], ':id' => $_REQUEST['id']));
    // Delete from department
    $query = "DELETE FROM {$GLOBALS['CONFIG']['db_prefix']}department where id = :id";
    $stmt = $pdo->prepare($query);
    $stmt->execute(array(':id' => $_REQUEST['id']));
    // back to main page
    $last_message = urlencode(msg('message_all_actions_successfull') . ' id:' . (int) $_REQUEST['id']);
    header('Location: admin.php?last_message=' . $last_message);
} elseif (isset($_REQUEST['submit']) && $_REQUEST['submit'] == 'modify') {
    $dept_obj = new Department($_REQUEST['item'], $pdo);
    draw_header(msg('area_update_department') . ': ' . $dept_obj->getName(), $last_message);
    ?>
  
                        <form action="department.php" id="modifyDeptForm" method="POST" enctype="multipart/form-data">                                        
                            <table border="0" cellspacing="5" cellpadding="5">
                                
                                    <tr>
                                            <?php 
    $query = "SELECT id, name FROM {$GLOBALS['CONFIG']['db_prefix']}department where id = :item";
    $stmt = $pdo->prepare($query);
    $stmt->execute(array(':item' => $_REQUEST['item']));
    $result = $stmt->fetchAll();
    foreach ($result as $row) {
        ?>
                                        <td>
                                            <b><?php 
Exemplo n.º 3
0
 /**
  * Delete a department from database with the passed ID.
  */
 public static function delDepartment($departmentId)
 {
     $dept = new Department($departmentId);
     if ($dept->id == 0) {
         // Department wasn't loaded correctly
         NQ::simple('intern', INTERN_ERROR, "Error occurred while loading department from database.");
         return;
     }
     $name = $dept->getName();
     try {
         // Try to delete department.
         if (!$dept->delete()) {
             // Something bad happend. This should have been caught in the check above...
             NQ::simple('intern', INTERN_SUCCESS, "Error occurred deleting department from database.");
             return;
         }
     } catch (Exception $e) {
         NQ::simple('intern', INTERN_ERROR, $e->getMessage());
         return;
     }
     // Department deleted successfully.
     NQ::simple('intern', INTERN_SUCCESS, "Deleted department <i>{$name}</i>");
 }
Exemplo n.º 4
0
 public static function sendInternshipCancelNotice(Internship $i)
 {
     $settings = InternSettings::getInstance();
     $tpl = array();
     $tpl['NAME'] = $i->getFullName();
     $tpl['BANNER'] = $i->banner;
     $tpl['TERM'] = Term::rawToRead($i->term);
     $dept = new Department($i->department_id);
     $tpl['DEPARTMENT'] = $dept->getName();
     $to = $i->email . '@appstate.edu';
     $faculty = $i->getFaculty();
     if ($faculty instanceof Faculty) {
         $cc = array($faculty->getUsername() . '@' . $settings->getEmailDomain(), $settings->getRegistrarEmail());
     } else {
         $cc = array();
     }
     $subject = 'Internship Cancelled ' . Term::rawToRead($i->getTerm()) . '[' . $i->getBannerId() . '] ' . $i->getFullName();
     Email::sendTemplateMessage($to, $subject, 'email/StudentCancellationNotice.tpl', $tpl, $cc);
 }
    }
    $c->save();
    echo "Category: {$c->getName()}\n";
}
// Now that we've got People and Categories in the database,
// Link the Departments with their Categories and Default Person
$result = $mongo->departments->find();
foreach ($result as $r) {
    $d = new Department($r['name']);
    if (!empty($r['defaultPerson']['_id'])) {
        $id = getPersonIdFromCrosswalk($r['defaultPerson']['_id']);
        $d->setDefaultPerson_id($id);
    }
    if (!empty($r['categories'])) {
        $ids = array();
        foreach ($r['categories'] as $c) {
            try {
                $category = new Category($c['name']);
                $ids[] = $category->getId();
            } catch (Exception $e) {
                // Departments may have old categories we have deleted
                // Just ignore them
            }
        }
        $d->setCategories($ids);
    }
    $d->save();
    $p = $d->getDefaultPerson();
    $p = $p ? $p->getFullname() : '';
    echo "Department: {$d->getName()} Person: {$p}\n";
}
Exemplo n.º 6
0
 function processvariablesAction()
 {
     $session = SessionWrapper::getInstance();
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender(TRUE);
     $formvalues = $this->_getAllParams();
     // debugMessage($formvalues); // exit;
     if (isArrayKeyAnEmptyString('noreload', $formvalues)) {
         $hasnoreload = false;
     } else {
         $hasnoreload = true;
     }
     $haserror = false;
     if (isArrayKeyAnEmptyString('value', $formvalues) && !$hasnoreload) {
         $haserror = true;
         $session->setVar(ERROR_MESSAGE, 'Error: No value specified for addition');
         $session->setVar(FORM_VALUES, $formvalues);
         $this->_helper->redirector->gotoUrl($this->view->baseUrl('config/variables/' . $formvalues['lookupid']));
     }
     $successurl = $this->view->baseUrl('config/variables/type/' . $formvalues['lookupid']);
     $type_ext = '';
     $alias = '';
     if (!isArrayKeyAnEmptyString('alias', $formvalues)) {
         $alias = trim($formvalues['alias']);
         if ($alias == 'undefined') {
             $alias = '';
         }
     }
     if ($formvalues['lookupid'] == 7) {
         $alias = decode($formvalues['alias']);
         if (isArrayKeyAnEmptyString('id', $formvalues)) {
             $alias = $formvalues['alias'];
         }
     }
     // exit;
     // debugMessage()
     switch ($formvalues['lookupid']) {
         case 9:
             $formvalues['defaultamount'] = $formvalues['alias'];
             if (!isArrayKeyAnEmptyString('id', $formvalues)) {
                 $formvalues['defaultamount'] = decode($formvalues['alias']);
             }
             $formvalues['amounttype'] = $formvalues['alias2'];
             $formvalues['name'] = decode(trim($formvalues['value']));
             if (!isArrayKeyAnEmptyString('id', $formvalues)) {
                 $formvalues['name'] = $formvalues['name'];
             }
             $formvalues['companyid'] = getCompanyID();
             $benefittype = new BenefitType();
             if (!isArrayKeyAnEmptyString('id', $formvalues)) {
                 $benefittype->populate($formvalues['id']);
                 $formvalues['lastupdatedby'] = $session->getVar('userid');
             } else {
                 $formvalues['createdby'] = $session->getVar('userid');
             }
             $benefittype->processPost($formvalues);
             /* debugMessage($benefittype->toArray());
             			debugMessage('errors are '.$benefittype->getErrorStackAsString()); exit(); */
             $result = array('id' => '', 'name' => '', 'error' => '');
             if ($benefittype->hasError()) {
                 $session->setVar(ERROR_MESSAGE, $benefittype->getErrorStackAsString());
                 $session->setVar(FORM_VALUES, $formvalues);
                 $result['error'] = $benefittype->getErrorStackAsString();
             } else {
                 try {
                     $benefittype->save();
                     // debugMessage($benefittype->toArray()); exit;
                     $result = array('id' => $benefittype->getID(), 'name' => $benefittype->getName(), 'alias' => $benefittype->getdefaultamount(), 'alias2' => $benefittype->getamounttype());
                     $session->setVar(SUCCESS_MESSAGE, "Successfully saved");
                 } catch (Exception $e) {
                     $session->setVar(ERROR_MESSAGE, $e->getMessage() . "<br />" . $benefittype->getErrorStackAsString());
                     $session->setVar(FORM_VALUES, $formvalues);
                     $result['error'] = $benefittype->getErrorStackAsString();
                 }
             }
             break;
         case 11:
             $formvalues['name'] = trim($formvalues['value']);
             $department = new Department();
             if (!isArrayKeyAnEmptyString('id', $formvalues)) {
                 $department->populate($formvalues['id']);
                 $formvalues['lastupdatedby'] = $session->getVar('userid');
             } else {
                 $formvalues['createdby'] = $session->getVar('userid');
             }
             $formvalues['companyid'] = getCompanyID();
             $department->processPost($formvalues);
             /* debugMessage($department->toArray());
             			debugMessage('errors are '.$department->getErrorStackAsString()); // exit(); */
             $result = array('id' => '', 'name' => '', 'error' => '');
             if ($department->hasError()) {
                 $session->setVar(ERROR_MESSAGE, $department->getErrorStackAsString());
                 $session->setVar(FORM_VALUES, $formvalues);
                 $result['error'] = $department->getErrorStackAsString();
             } else {
                 try {
                     $department->save();
                     $result = array('id' => $department->getID(), 'name' => $department->getName(), 'error' => '');
                     $session->setVar(SUCCESS_MESSAGE, "Successfully saved");
                 } catch (Exception $e) {
                     $session->setVar(ERROR_MESSAGE, $e->getMessage() . "<br />" . $department->getErrorStackAsString());
                     $session->setVar(FORM_VALUES, $formvalues);
                     $result['error'] = $department->getErrorStackAsString();
                 }
             }
             break;
         default:
             $lookupvalue = new LookupTypeValue();
             $lookuptype = new LookupType();
             $lookuptype->populate($formvalues['lookupid']);
             $index = '';
             if ($hasnoreload) {
                 $index = $lookuptype->getNextInsertIndex();
                 $value = trim($formvalues['value']);
             } else {
                 if (!isArrayKeyAnEmptyString('index', $formvalues)) {
                     $index = $formvalues['index'];
                 } else {
                     $index = $lookuptype->getNextInsertIndex();
                 }
                 $value = addslashes(decode(trim($formvalues['value'])));
             }
             $dataarray = array('id' => $formvalues['id'], 'lookuptypeid' => $formvalues['lookupid'], 'lookuptypevalue' => $index, 'lookupvaluedescription' => $value, 'alias' => $alias, 'createdby' => $session->getVar('userid'), 'companyid' => getCompanyID());
             // debugMessage($dataarray);
             if (!isArrayKeyAnEmptyString('id', $formvalues)) {
                 $lookupvalue->populate($formvalues['id']);
                 $beforesave = $lookupvalue->toArray();
                 // debugMessage($beforesave);
             }
             // unset($dataarray['id']);
             $lookupvalue->processPost($dataarray);
             /* debugMessage($lookupvalue->toArray());
               	debugMessage('errors are '.$lookupvalue->getErrorStackAsString()); exit(); */
             $result = array('id' => '', 'name' => '', 'error' => '');
             if ($lookupvalue->hasError()) {
                 $haserror = true;
                 $session->setVar(ERROR_MESSAGE, $lookupvalue->getErrorStackAsString());
                 $session->setVar(FORM_VALUES, $formvalues);
                 $result['error'] = $lookupvalue->getErrorStackAsString();
             } else {
                 try {
                     $lookupvalue->save();
                     if (!$hasnoreload) {
                         $url = $this->view->serverUrl($this->view->baseUrl("config/variables/lookupid/" . $formvalues['lookupid']));
                         $module = '0';
                         if (isArrayKeyAnEmptyString('id', $formvalues)) {
                             $session->setVar(SUCCESS_MESSAGE, "Successfully saved");
                             $type = SYSTEM_ADDVARIABLE;
                             $usecase = '0.1';
                             $details = 'Variable - <b>' . $lookupvalue->getlookupvaluedescription() . ' </b>(' . $lookupvalue->getLookupType()->getdisplayname() . ') addded';
                         } else {
                             $session->setVar(SUCCESS_MESSAGE, "Successfully updated");
                             $type = SYSTEM_UPDATEVARIABLE;
                             $usecase = '0.2';
                             $details = 'Variable - <b>' . $lookupvalue->getlookupvaluedescription() . ' </b>(' . $lookupvalue->getLookupType()->getdisplayname() . ') updated';
                             $prejson = json_encode($beforesave);
                             $lookupvalue->clearRelated();
                             $after = $lookupvalue->toArray();
                             // debugMessage($after);
                             $postjson = json_encode($after);
                             // debugMessage($postjson);
                             $diff = array_diff($beforesave, $after);
                             // debugMessage($diff);
                             $jsondiff = json_encode($diff);
                             // debugMessage($jsondiff);
                         }
                         $browser = new Browser();
                         $audit_values = $session->getVar('browseraudit');
                         $audit_values['module'] = $module;
                         $audit_values['usecase'] = $usecase;
                         $audit_values['transactiontype'] = $type;
                         $audit_values['status'] = "Y";
                         $audit_values['userid'] = $session->getVar('userid');
                         $audit_values['transactiondetails'] = $details;
                         $audit_values['url'] = $url;
                         if (!isArrayKeyAnEmptyString('id', $formvalues)) {
                             $audit_values['isupdate'] = 1;
                             $audit_values['prejson'] = $prejson;
                             $audit_values['postjson'] = $postjson;
                             $audit_values['jsondiff'] = $jsondiff;
                         }
                         // debugMessage($audit_values);
                         $this->notify(new sfEvent($this, $type, $audit_values));
                     }
                     $result = array('id' => $lookupvalue->getlookuptypevalue(), 'name' => $lookupvalue->getlookupvaluedescription(), 'alias' => $lookupvalue->getalias(), 'error' => '');
                 } catch (Exception $e) {
                     $session->setVar(ERROR_MESSAGE, $e->getMessage() . "<br />" . $lookupvalue->getErrorStackAsString());
                     $session->setVar(FORM_VALUES, $formvalues);
                 }
             }
             break;
     }
     // debugMessage($successurl);exit();
     if (!$hasnoreload) {
         $this->_helper->redirector->gotoUrl($successurl);
     } else {
         echo json_encode($result);
     }
 }
Exemplo n.º 7
0
    } elseif (array_key_exists($row['dept_name'], $lookup)) {
        $person = new Person($lookup[$row['dept_name']]);
    }
    if (isset($person)) {
        $department = new Department();
        $department->setName($row['dept_name']);
        $department->setDefaultPerson($person);
        $query->closeCursor();
        // Load the Department's commonly used categories
        $sql = "select distinct c.comp_desc\n\t\t\t\tfrom ce_eng_comp a,c_types c\n\t\t\t\twhere a.c_type=c.c_type1 and a.dept=?\n\t\t\t\tand a.c_type is not null\n\t\t\t\tand a.c_type!=0\n\t\t\t\torder by c.comp_desc";
        $query = $pdo->prepare($sql);
        $query->execute(array($row['dept_no']));
        $department->setCategories($query->fetchAll(PDO::FETCH_COLUMN));
        try {
            $department->save();
            echo $department->getName() . "\n";
        } catch (Exception $e) {
            print_r($e);
            print_r($department);
            print_r($person);
            exit;
        }
    }
}
// Assign all the users to their departments
$sql = "select u.userid,d.dept_name\n\t\tfrom complain_authorized u,departments d\n\t\twhere u.dept=d.dept_no and u.userid=?";
$query = $pdo->prepare($sql);
$people = new PersonList(array('username' => array('$exists' => true)));
foreach ($people as $person) {
    $query->execute(array($person->getUsername()));
    $row = $query->fetch(PDO::FETCH_ASSOC);