Ejemplo n.º 1
0
 function getStaffTeams($staff_id)
 {
     $sql = "select  * from " . TEAM_MEMBER_TABLE . " where staff_id=" . $staff_id;
     if (!($res = db_query($sql)) || !db_num_rows($res)) {
         return "";
     } else {
         $teams = "";
         while ($row = db_fetch_array($res)) {
             if ($team = Team::lookup(intval($row['team_id']))) {
                 if ($teamname = $team->getName()) {
                     $teams = $teams . stripslashes($teamname);
                 }
             }
         }
         return trim($teams);
     }
 }
Ejemplo n.º 2
0
if($userInfoArray = Staff::getStaffCSVFile())
{
	// echo json_encode($userInfoArray);
	foreach ($userInfoArray as $fields) {
			// echo json_encode(array($fields['username'],$fields['firstname'],$fields['lastname'],$fields['isadmin'],$fields['onvacation'],$fields['created'],$fields['lastlogin'],Staff::getStaffTeams($fields['staff_id'])));
		fprintf($fp, chr(0xEF).chr(0xBB).chr(0xBF));
		// fputcsv($fp,$fields);
		$teams = Staff::getStaffTeams($fields['staff_id']);
		// logErrors(json_encode(Team::getActiveTeams()));
		// echo $teams;
		html_entity_decode(mb_convert_encoding(stripslashes($teams), "HTML-ENTITIES", 'UTF-8'));
		try {
			$resultArray = array($fields['username'],$fields['firstname'],$fields['lastname'],booleanToString($fields['isadmin']),$fields['created'],$fields['lastlogin']);
			foreach ($teamsArray as $key=>$value) {
				// logErrors("team id: ".$key);
				if($team = Team::lookup(intval($key)))
				{
					logErrors(json_encode($team->getName()));
					array_push($resultArray,booleanToString($team->hasMember(Staff::lookup(intval($fields['staff_id'])))));	
				}
			}
			// logErrors(json_encode($resultArray));
			fputcsv($fp,$resultArray);
	    // fputcsv($fp, array_merge(array($fields['username'],$fields['firstname'],$fields['lastname'],$fields['isadmin'],$fields['onvacation'],$fields['created'],$fields['lastlogin']),null));
		
		} catch (Exception $e) {
			logErrors('Caught exception: ',  $e->getMessage(), "\n");
		}
	}

}
Ejemplo n.º 3
0
 function assignToTeam($team, $note, $alert = true)
 {
     if (!is_object($team) && !($team = Team::lookup($team))) {
         return false;
     }
     if (!$this->setTeamId($team->getId())) {
         return false;
     }
     //Clear - staff if it's a closed ticket
     //  staff_id is overloaded -> assigned to & closed by.
     if ($this->isClosed()) {
         $this->setStaffId(0);
     }
     $this->onAssign($note, $alert);
     return true;
 }
Ejemplo n.º 4
0
             break;
         case 'disable':
             $sql = 'UPDATE ' . TEAM_TABLE . ' SET isenabled=0 ' . ' WHERE team_id IN (' . implode(',', db_input($_POST['ids'])) . ')';
             if (db_query($sql) && ($num = db_affected_rows())) {
                 if ($num == $count) {
                     $msg = sprintf(__('Successfully disabled %s'), _N('selected team', 'selected teams', $count));
                 } else {
                     $warn = sprintf(__('%1$d of %2$d %3$s disabled'), $num, $count, _N('selected team', 'selected teams', $count));
                 }
             } else {
                 $errors['err'] = sprintf(__('Unable to disable %s'), _N('selected team', 'selected teams', $count));
             }
             break;
         case 'delete':
             foreach ($_POST['ids'] as $k => $v) {
                 if (($t = Team::lookup($v)) && $t->delete()) {
                     $i++;
                 }
             }
             if ($i && $i == $count) {
                 $msg = sprintf(__('Successfully deleted %s'), _N('selected team', 'selected teams', $count));
             } elseif ($i > 0) {
                 $warn = sprintf(__('%1$d of %2$d %3$s deleted'), $i, $count, _N('selected team', 'selected teams', $count));
             } elseif (!$errors['err']) {
                 $errors['err'] = sprintf(__('Unable to delete %s'), _N('selected team', 'selected teams', $count));
             }
             break;
         default:
             $errors['err'] = __('Unknown action - get technical help.');
     }
 }
Ejemplo n.º 5
0
 function update($vars, &$errors)
 {
     $valid = true;
     $forms = $this->getForms($vars);
     foreach ($forms as $cd) {
         if (!$cd->isValid()) {
             $valid = false;
         }
         if ($cd->get('type') == 'O' && ($form = $cd->getForm($vars)) && ($f = $form->getField('name')) && $f->getClean() && ($o = Organization::lookup(array('name' => $f->getClean()))) && $o->id != $this->getId()) {
             $valid = false;
             $f->addError('Organization with the same name already exists');
         }
     }
     if ($vars['domain']) {
         foreach (explode(',', $vars['domain']) as $d) {
             if (!Validator::is_email('t@' . trim($d))) {
                 $errors['domain'] = 'Enter a valid email domain, like domain.com';
             }
         }
     }
     if ($vars['manager']) {
         switch ($vars['manager'][0]) {
             case 's':
                 if ($staff = Staff::lookup(substr($vars['manager'], 1))) {
                     break;
                 }
             case 't':
                 if ($vars['manager'][0] == 't' && ($team = Team::lookup(substr($vars['manager'], 1)))) {
                     break;
                 }
             default:
                 $errors['manager'] = 'Select a staff member or team from the list';
         }
     }
     if (!$valid || $errors) {
         return false;
     }
     foreach ($this->getDynamicData() as $cd) {
         if (($f = $cd->getForm()) && $f->get('type') == 'O' && ($name = $f->getField('name'))) {
             $this->name = $name->getClean();
             $this->save();
         }
         $cd->save();
     }
     // Set flags
     foreach (array('collab-all-flag' => Organization::COLLAB_ALL_MEMBERS, 'collab-pc-flag' => Organization::COLLAB_PRIMARY_CONTACT, 'assign-am-flag' => Organization::ASSIGN_AGENT_MANAGER) as $ck => $flag) {
         if ($vars[$ck]) {
             $this->setStatus($flag);
         } else {
             $this->clearStatus($flag);
         }
     }
     // Set staff and primary contacts
     $this->set('domain', $vars['domain']);
     $this->set('manager', $vars['manager'] ?: '');
     if ($vars['contacts'] && is_array($vars['contacts'])) {
         foreach ($this->allMembers() as $u) {
             $u->setPrimaryContact(array_search($u->id, $vars['contacts']) !== false);
             $u->save();
         }
     }
     return $this->save();
 }