Example #1
0
 function score_entry_display()
 {
     global $dbh;
     $sth = $dbh->prepare('SELECT * FROM score_entry WHERE team_id = ? AND game_id = ?');
     $sth->execute(array($this->game->home_team, $this->game->game_id));
     $home = $sth->fetch();
     if (!$home) {
         $home = array('score_for' => 'not entered', 'score_against' => 'not entered', 'defaulted' => 'no');
     } else {
         $entry_person = Person::load(array('user_id' => $home['entered_by']));
         $home['entered_by'] = l($entry_person->fullname, "person/view/{$entry_person->user_id}");
     }
     $sth->execute(array($this->game->away_team, $this->game->game_id));
     $away = $sth->fetch();
     if (!$away) {
         $away = array('score_for' => 'not entered', 'score_against' => 'not entered', 'defaulted' => 'no');
     } else {
         $entry_person = Person::load(array('user_id' => $away['entered_by']));
         $away['entered_by'] = l($entry_person->fullname, "person/view/{$entry_person->user_id}");
     }
     $header = array(" ", $this->game->home_name . ' (home)', $this->game->away_name . ' (away)');
     $rows = array();
     $rows[] = array("Home Score:", $home['score_for'], $away['score_against']);
     $rows[] = array("Away Score:", $home['score_against'], $away['score_for']);
     $rows[] = array("Defaulted?", $home['defaulted'], $away['defaulted']);
     $rows[] = array("Entered By:", $home['entered_by'], $away['entered_by']);
     $rows[] = array("Entry time:", $home['entry_time'], $away['entry_time']);
     return '<div class="listtable">' . table($header, $rows) . "</div>";
 }
Example #2
0
 public function _new()
 {
     parent::_new();
     $this->setTemplateName('calls_new');
     $projects = $opportunities = $activities = null;
     if (isset($this->_data['person_id'])) {
         $person = new Person();
         $person->load($this->_data['person_id']);
         $this->_data['company_id'] = $person->company_id;
         $projects = $person->projects;
         $opportunities = $person->opportunities;
         $activities = $person->activities;
         $this->view->set('person', $person->fullname);
     }
     if (isset($this->_data['company_id'])) {
         $company = new Company();
         $company->load($this->_data['company_id']);
         $projects = DataObjectCollection::Merge($company->projects, $projects);
         $opportunities = DataObjectCollection::Merge($company->opportunities, $opportunities);
         $activities = DataObjectCollection::Merge($company->activities, $activities);
         $this->view->set('company', $company->name);
     }
     if (isset($this->_data['project_id'])) {
         $project = new Project();
         $project->load($this->_data['project_id']);
         $this->_data['company_id'] = $project->company_id;
     }
     $this->view->set('projects', $projects);
     $this->view->set('opportunities', $opportunities);
     $this->view->set('activities', $activities);
 }
Example #3
0
    function load()
    {
        global $dbh;
        $returnValue = false;
        if (parent::load()) {
            $query = '
SELECT
	  `IDNumber`
	, `KRAPIN`
	, `dateOfEmployment`
FROM
	`employeeDetails`
WHERE
	`uniqueID` = "' . mysql_escape_string($this->getUniqueID()) . '"
';
            try {
                $statement = $dbh->prepare($query);
                $statement->execute();
                $row = $statement->fetch();
                $this->setIDNumber(mysql_escape_string($row["IDNumber"]));
                $this->setKRAPIN(mysql_escape_string($row["KRAPIN"]));
                $this->setDateOfEmployment(mysql_escape_string($row["dateOfEmployment"]));
                $returnValue = true;
            } catch (PDOException $e) {
                print "Error!: " . $e->getMessage() . "<br/>";
                die;
            }
            $returnValue = true;
        }
        return $returnValue;
    }
Example #4
0
 public static function GetRecipients($ticket)
 {
     $recipients = array();
     if ($ticket->originator_person_id != null) {
         // If this ticket has a person, attempt to send mail to them
         $person = new Person();
         $person->load($ticket->originator_person_id);
         $contact = $person->email->contactmethod;
         if (!empty($contact)) {
             $recipients[] = $contact;
         } else {
             // If no contact found then reiterate but for company contacts this time
             if ($ticket->originator_company_id != null) {
                 $contact = $ticket->getCompanyEmail($ticket->originator_company_id);
                 if (!empty($contact)) {
                     $recipients[] = $contact;
                 }
             }
         }
     }
     // Last ditch effort.
     if (count($recipients) == 0) {
         if (!is_null($ticket->originator_email_address)) {
             $recipients[] = $ticket->originator_email_address;
         }
     }
     return $recipients;
 }
Example #5
0
 function user()
 {
     if (!$this->user_id) {
         return null;
     }
     return Person::load(array('user_id' => $this->user_id));
 }
Example #6
0
 function perform($edit = array())
 {
     $fields = array();
     if (validate_nonblank($edit['username'])) {
         $fields['username'] = $edit['username'];
     }
     if (validate_nonblank($edit['email'])) {
         $fields['email'] = $edit['email'];
     }
     if (count($fields) < 1) {
         error_exit("You must supply at least one of username or email address");
     }
     /* Now, try and find the user */
     $user = Person::load($fields);
     /* Now, we either have one or zero users.  Regardless, we'll present
      * the user with the same output; that prevents them from using this
      * to guess valid usernames.
      */
     if ($user) {
         /* Generate a password */
         $pass = generate_password();
         $user->set_password($pass);
         if (!$user->save()) {
             error_exit("Error setting password");
         }
         /* And fire off an email */
         $rc = send_mail($user, false, false, _person_mail_text('password_reset_subject', array('%site' => variable_get('app_name', 'Leaguerunner'))), _person_mail_text('password_reset_body', array('%fullname' => "{$user->firstname} {$user->lastname}", '%username' => $user->username, '%password' => $pass, '%site' => variable_get('app_name', 'Leaguerunner'))));
         if ($rc == false) {
             error_exit("System was unable to send email to that user.  Please contact system administrator.");
         }
     }
 }
Example #7
0
 public function systemCompany(&$do, &$errors)
 {
     $user = getCurrentUser();
     $person = new Person();
     $person->load($user->person_id);
     $format = new xmlrpcmsg('elgg.user.newCommunity', array(new xmlrpcval($person->firstname . ' ' . $person->surname, "string"), new xmlrpcval($person->email, "string"), new xmlrpcval($do->company, "string")));
     $client = new xmlrpc_client("_rpc/RPC2.php", "tech2.severndelta.co.uk", 8091);
     $request = $client->send($format);
     if (!$request->faultCode()) {
         $response = $request->value();
         if ($response->structmemexists('owner') && $response->structmemexists('community')) {
             $person->published_username = $response->structmem('owner')->scalarval();
             $person->save();
             $do->published = true;
             $do->published_username = $response->structmem('community')->scalarval();
             $do->published_owner_id = $person->id;
             $do->save();
         } else {
             $errors[] = 'Failed to publish company';
         }
     } else {
         $errors[] = "Code: " . $request->faultCode() . " Reason '" . $request->faultString();
         return false;
     }
     return true;
 }
Example #8
0
 public function viewperson()
 {
     $view = new Newsletterview();
     $view->load($this->_data['id']) or sendBack();
     $person = new Person();
     $person->load($view->person_id);
     sendTo('persons', 'view', 'contacts', array('id' => $person->id));
 }
Example #9
0
 function __construct($id, $player_id = null)
 {
     parent::__construct($id);
     if ($player_id) {
         $this->player = Person::load(array('user_id' => $player_id));
     }
     $this->template_name = 'pages/team/roster.tpl';
 }
Example #10
0
 function __construct($id)
 {
     $this->person = Person::load(array('user_id' => $id));
     if (!$this->person) {
         error_exit("That user does not exist");
     }
     person_add_to_menu($this->person);
 }
Example #11
0
 function __construct($id)
 {
     global $lr_session;
     if ($id) {
         $this->person = Person::load(array('user_id' => $id));
     }
     if (!$this->person) {
         $this->person =& $lr_session->user;
     }
 }
Example #12
0
 function __construct($event_id, $registrant_id = null)
 {
     global $lr_session;
     if ($lr_session->is_admin() && !is_null($registrant_id)) {
         $this->registrant_id = $registrant_id;
         if ($this->registrant_id != 'choose') {
             $this->registrant = Person::load(array('user_id' => $registrant_id));
         }
     } else {
         $this->registrant_id = $lr_session->user->user_id;
         $this->registrant = $lr_session->user;
     }
     parent::__construct($event_id, $this->registrant);
 }
Example #13
0
 function check_input_errors($edit = array())
 {
     $errors = parent::check_input_errors($edit);
     if (!validate_name_input($edit['username'])) {
         $errors[] = "You can only use letters, numbers, spaces, and the characters - ' and . in usernames";
     }
     $existing_user = Person::load(array('username' => $edit['username']));
     if ($existing_user) {
         $errors[] = "A user with that username already exists; please choose another";
     }
     if ($edit['password_once'] != $edit['password_twice']) {
         $errors[] = error_exit("First and second entries of password do not match");
     }
     return $errors;
 }
    function load($id)
    {
        $res = parent::load($id);
        // Load restrictions
        $sql = 'SELECT congregationid, NULL as groupid 
				FROM account_congregation_restriction
				WHERE personid = ' . (int) $id . '
				UNION
				SELECT NULL as congregationid, groupid
				FROM account_group_restriction 
				WHERE personid = ' . (int) $id;
        $res = $GLOBALS['db']->queryAll($sql);
        check_db_result($res);
        foreach ($res as $row) {
            $type = empty($row['congregationid']) ? 'group' : 'congregation';
            $this->_restrictions[$type][] = $row[$type . 'id'];
        }
        return $res;
    }
Example #15
0
 function process()
 {
     global $lr_session;
     $this->title = "{$this->league->fullname} &raquo; Member Status";
     if (!$this->player_id) {
         $new_handler = new person_search();
         $new_handler->smarty =& $this->smarty;
         $new_handler->initialize();
         $new_handler->ops['Add to ' . $this->league->fullname] = 'league/member/' . $this->league->league_id;
         $new_handler->extra_where = "(class = 'administrator' OR class = 'volunteer')";
         $new_handler->process();
         $this->template_name = $new_handler->template_name;
         return true;
     }
     if (!$lr_session->is_admin() && $this->player_id == $lr_session->attr_get('user_id')) {
         error_exit("You cannot add or remove yourself as league coordinator");
     }
     $player = Person::load(array('user_id' => $this->player_id));
     switch ($_GET['edit']['status']) {
         case 'remove':
             if (!$this->league->remove_coordinator($player)) {
                 error_exit("Failed attempting to remove coordinator from league");
             }
             break;
         default:
             if ($player->class != 'administrator' && $player->class != 'volunteer') {
                 error_exit("Only volunteer-class players can be made coordinator");
             }
             if (!$this->league->add_coordinator($player)) {
                 error_exit("Failed attempting to add coordinator to league");
             }
             break;
     }
     if (!$this->league->save()) {
         error_exit("Failed attempting to modify coordinators for league");
     }
     local_redirect(url("league/view/" . $this->league->league_id));
 }
Example #16
0
    function load($returnType = RETURN_BOOLEAN)
    {
        global $dbh;
        $query = '
SELECT
	  `schoolID`
	, `dateOfAdmission`
	, `yearOfStudyAtAdmission`
	, `gender`
	, `entryScore`  
FROM
	`studentDetails`
WHERE
	`uniqueID` = "' . mysql_escape_string($this->getUniqueID()) . '"
';
        $query_subjects = '
SELECT
	`subjectCode`
FROM
	`studentSubjects`
WHERE
	`studentID` = "' . $this->getUniqueID() . '"';
        if ($returnType == 0) {
            $returnValue = false;
            if (parent::load()) {
                try {
                    $statement = $dbh->prepare($query);
                    $statement->execute();
                    $row = $statement->fetch();
                    $this->setSchoolID($row["schoolID"]);
                    $this->setDateOfAdmission($row["dateOfAdmission"]);
                    $this->setYearOfStudyAtAdmission($row["yearOfStudyAtAdmission"]);
                    $this->setGender($row["gender"]);
                    $this->setEntryScore($row["entryScore"]);
                    $returnValue = true;
                } catch (PDOException $e) {
                    print "Error!: " . $e->getMessage() . "<br/>";
                    die;
                }
                $returnValue = true;
            }
        } else {
            $returnType = $query;
        }
        return $returnValue;
    }
Example #17
0
 private function notifyQueueOwner($ticket, $data)
 {
     // Needs to be Assigned To if present
     // otherwise Queue Owner
     $plateout = TicketingUtils::StatusPlate($ticket);
     $to = '';
     if (!is_null($ticket->assigned_to)) {
         $user = new User();
         $user->loadBy('username', $ticket->assigned_to);
         if (!is_null($user->person_id)) {
             $person = new Person();
             $person->load($user->person_id);
             $to = $person->email->contactmethod;
         }
         if (empty($to)) {
             $to = $user->email;
         }
     }
     if (empty($to)) {
         $queue = new TicketQueue();
         $queue->load($ticket->ticket_queue_id);
         if ($queue->isLoaded() && !is_null($queue->email_address)) {
             $to = $queue->email_address;
         }
     }
     if (!empty($to)) {
         $headers = array('From' => TicketingUtils::getReplyAddress($ticket), 'Reply-To' => $data['reply_address']);
         $header_string = "";
         foreach ($headers as $header => $value) {
             $header_string .= $header . ': ' . $value . "\r\n";
         }
         $body = $plateout . "\n" . $data['message'] . "\n";
         mail($to, 're: [' . $ticket->ticket_queue_id . '-' . $ticket->id . '] ' . $ticket->summary, $body, $header_string, '-r ' . $to);
     }
 }
Example #18
0
 /**
  * Create the user session from the given username and password
  *
  * @return boolean status of session creation
  */
 function create_from_login($username, $password, $client_ip)
 {
     if (!isset($username)) {
         return false;
     }
     if (!isset($password)) {
         return false;
     }
     $user = Person::load(array('username' => $username));
     if (!$user) {
         return false;
     }
     # Check password
     if (!$user->check_password($password)) {
         return false;
     }
     /* Ok, the user is good.  Now we need to save the user
      * and generate a session key.
      */
     $this->user = $user;
     $this->session_key = session_id();
     if (!$this->user->log_in($this->session_key, $client_ip, $password)) {
         return false;
     }
     return true;
 }
Example #19
0
 public function save()
 {
     // Fill client hidden sections
     $user = new User();
     $person = new Person();
     $user->load(EGS_USERNAME);
     if (!is_null($user->person_id)) {
         $person->load($user->person_id);
     }
     // Is this quick entry?
     if ($this->_data['TicketResponse']['type'] == 'quick') {
         $this->_data['TicketResponse']['type'] = 'site';
         $config = new TicketConfigurationCollection(new TicketConfiguration());
         $sh = new SearchHandler($config);
         $sh->AddConstraint(new Constraint('usercompanyid', '=', EGS_COMPANY_ID));
         $config->load($sh);
         $config = $config->getContents();
         if (count($config) !== 1) {
             // Make one.
             $newConfig['usercompanyid'] = EGS_COMPANY_ID;
             $priority = self::findDefault(new TicketPriorityCollection(new TicketPriority()));
             $newConfig['client_ticket_priority_default'] = $priority->id;
             $newConfig['internal_ticket_priority_default'] = $priority->id;
             $severity = self::findDefault(new TicketSeverityCollection(new TicketSeverity()));
             $newConfig['client_ticket_severity_default'] = $severity->id;
             $newConfig['internal_ticket_severity_default'] = $severity->id;
             $queue = self::findDefault(new TicketQueueCollection(new TicketQueue()));
             $newConfig['ticket_queue_default'] = $queue->id;
             $category = self::findDefault(new TicketCategoryCollection(new TicketCategory()));
             $newConfig['ticket_category_default'] = $category->id;
             $status = self::findDefault(new TicketStatusCollection(new TicketStatus()));
             $newConfig['client_ticket_status_default'] = $status->id;
             $newConfig['internal_ticket_status_default'] = $status->id;
             $config = TicketConfiguration::Factory($newConfig);
         } else {
             $config = $config[0];
         }
         $this->_data['Ticket']['client_ticket_priority_id'] = $config->client_ticket_priority_default;
         $this->_data['Ticket']['ticket_queue_id'] = $config->ticket_queue_default;
     }
     $this->_data['Ticket']['originator_person_id'] = $user->username;
     $this->_data['Ticket']['originator_company_id'] = $user->lastcompanylogin;
     $this->_data['Ticket']['internal_ticket_severity_id'] = $this->_data['Ticket']['client_ticket_severity_id'];
     $this->_data['Ticket']['internal_ticket_priority_id'] = $this->_data['Ticket']['client_ticket_priority_id'];
     if (!isset($this->_data['Ticket']['id'])) {
         // Force 'new' status initialy
         $ts = new TicketStatusCollection(new TicketStatus());
         $sh = new SearchHandler($ts);
         $sh->addConstraint(new Constraint('usercompanyid', '=', EGS_COMPANY_ID));
         $sh->addConstraint(new Constraint('status_code', '=', 'NEW'));
         $ts->load($sh);
         $statuses = $ts->getContents();
         $status = $statuses[0];
         // Should only ever be one status, this should be regulated by earlier validation
         $this->_data['Ticket']['client_ticket_status_id'] = $status->id;
         $this->_data['Ticket']['internal_ticket_status_id'] = $status->id;
     }
     if (isset($this->_data['Ticket']['id'])) {
         $originalTicket = new Ticket();
         $originalTicket->load($this->_data['Ticket']['id']);
         $changes = array(array('param' => 'client_ticket_status_id', 'friendly' => 'Status', 'object' => 'TicketStatus'), array('param' => 'client_ticket_priority_id', 'friendly' => 'Priority', 'object' => 'TicketPriority'), array('param' => 'client_ticket_severity_id', 'friendly' => 'Severity', 'object' => 'TicketSeverity'), array('param' => 'ticket_queue_id', 'friendly' => 'Queue', 'object' => 'TicketQueue'));
         $changeText = array();
         foreach ($changes as $change) {
             if ($this->_data['Ticket'][$change['param']] != $originalTicket->{$change}['param']) {
                 $was = new $change['object']();
                 $now = new $change['object']();
                 $was->load($originalTicket->{$change}['param']);
                 $now->load($this->_data['Ticket'][$change['param']]);
                 $changeText[] = $change['friendly'] . ': was ' . $was->name . ' now ' . $now->name . '.';
             }
         }
         if (count($changeText) > 0) {
             $errors = array();
             $ticketResponse = TicketResponse::Factory(array('ticket_id' => $this->_data['Ticket']['id'], 'internal' => 'false', 'body' => implode("\n", $changeText), 'type' => 'status', 'owner' => EGS_USERNAME), $errors, 'TicketResponse');
             $ticketResponse->save();
             $queue = new TicketQueue();
             $queue->load($originalTicket->ticket_queue_id);
             // Send mail
             $headers = array('From' => $queue->email_address);
             $header_string = "";
             foreach ($headers as $header => $value) {
                 $header_string .= $header . ': ' . $value . "\r\n";
             }
             $body = TicketingUtils::StatusPlate($originalTicket) . implode("\n", $changeText);
             $recipients = TicketingUtils::GetRecipients($originalTicket);
             foreach ($recipients as $recipient) {
                 mail($recipient, 're: [' . $originalTicket->ticket_queue_id . '-' . $originalTicket->id . '] ' . $originalTicket->summary, $body, $header_string);
             }
         }
     }
     parent::save('Ticket');
     $ticket_id = $this->_data['id'];
     $this->_data['Ticket']['id'] = $this->_data['id'];
     if (isset($this->_data['id'])) {
         $this->_data['TicketResponse']['ticket_id'] = $ticket_id;
         parent::save('TicketResponse');
     }
     sendTo('Client', 'view', array('ticketing'), array('id' => $ticket_id));
 }
Example #20
0
 function check_input_errors($edit = array())
 {
     global $lr_session;
     $errors = array();
     if ($lr_session->has_permission('person', 'edit', $this->person->user_id, 'name')) {
         if (!validate_name_input($edit['firstname']) || !validate_name_input($edit['lastname'])) {
             $errors[] = "You can only use letters, numbers, spaces, and the characters - ' and . in first and last names";
         }
     }
     if ($lr_session->has_permission('person', 'edit', $this->person->user_id, 'username')) {
         if (!validate_name_input($edit['username'])) {
             $errors[] = "You can only use letters, numbers, spaces, and the characters - ' and . in usernames";
         }
         $user = Person::load(array('username' => $edit['username']));
         # TODO: BUG: need to check that $user->user_id != current id
         if ($user && !$lr_session->is_admin()) {
             $errors[] = "A user with that username already exists; please choose another";
         }
     }
     if (!validate_email_input($edit['email'])) {
         $errors[] = "You must supply a valid email address";
     }
     if (!validate_nonblank($edit['home_phone']) && !validate_nonblank($edit['work_phone']) && !validate_nonblank($edit['mobile_phone'])) {
         $errors[] = "You must supply at least one valid telephone number.  Please supply area code, number and (if any) extension.";
     }
     if (validate_nonblank($edit['home_phone']) && !validate_telephone_input($edit['home_phone'])) {
         $errors[] = "Home telephone number is not valid.  Please supply area code, number and (if any) extension.";
     }
     if (validate_nonblank($edit['work_phone']) && !validate_telephone_input($edit['work_phone'])) {
         $errors[] = "Work telephone number is not valid.  Please supply area code, number and (if any) extension.";
     }
     if (validate_nonblank($edit['mobile_phone']) && !validate_telephone_input($edit['mobile_phone'])) {
         $errors[] = "Mobile telephone number is not valid.  Please supply area code, number and (if any) extension.";
     }
     $address_errors = validate_address($edit['addr_street'], $edit['addr_city'], $edit['addr_prov'], $edit['addr_postalcode'], $edit['addr_country']);
     if (count($address_errors) > 0) {
         $errors = array_merge($errors, $address_errors);
     }
     if (!preg_match("/^[mf]/i", $edit['gender'])) {
         $errors[] = "You must select either male or female for gender.";
     }
     if (!validate_yyyymmdd_input($edit['birthdate'])) {
         $errors[] = "You must provide a valid birthdate";
     }
     if (validate_nonblank($edit['height'])) {
         if (!$lr_session->is_admin() && ($edit['height'] < 36 || $edit['height'] > 84)) {
             $errors[] = "Please enter a reasonable and valid value for your height.";
         }
     }
     if ($edit['skill_level'] < 1 || $edit['skill_level'] > 10) {
         $errors[] = "You must select a skill level between 1 and 10. You entered " . $edit['skill_level'];
     }
     $current = localtime(time(), 1);
     $this_year = $current['tm_year'] + 1900;
     if ($edit['year_started'] > $this_year) {
         $errors[] = "Year started must be before current year.";
     }
     if ($edit['year_started'] < 1986) {
         $errors[] = "Year started must be after 1986.  For the number of people who started playing before then, I don't think it matters if you're listed as having played 17 years or 20, you're still old. :)";
     }
     $birth_year = substr($edit['birthdate'], 0, 4);
     $yearDiff = $edit['year_started'] - $birth_year;
     if ($yearDiff < 8) {
         $errors[] = "You can't have started playing when you were {$yearDiff} years old!  Please correct your birthdate, or your starting year";
     }
     return $errors;
 }
Example #21
0
 function assoc_obj()
 {
     if (!$this->assoc_obj) {
         if ($this->assoc_type == 'person') {
             $this->assoc_obj = Person::load(array('user_id' => $this->assoc_id));
         } elseif ($this->assoc_type == 'team') {
             $this->assoc_obj = Team::load(array('team_id' => $this->assoc_id));
         } else {
             die("Invalid assoc_type of " . $this->assoc_type);
         }
     }
     return $this->assoc_obj;
 }
Example #22
0
$person = new Person();
$data = array('name' => 'Tommy', 'age' => '20', 'citizenship' => 'American');
$person->bind($data);
$person->add();
// Select les users par l'âge et l'id
$person = new Person();
$person->age = '20';
// $person->id='558';
$personlist = $person->loadMultiple();
foreach ($personlist as $person) {
    var_dump("{$person->name} {$person->age} {$person->citizenship} \r\n");
}
// Pour filtrer les recherches
$dbo->select('id', 'name', 'age')->from('person')->where('age=20')->limit(2)->result();
$personlist = $dbo->loadObjectList();
foreach ($personlist as $person) {
    echo "<br><br>";
    echo " Username: {$person['name']} <br>  Age: {$person['age']} <br> Id: {$person['id']} ";
}
$dbo->orderby('id');
// Remplace le USER dans la base de données par un autre
$person = new Person();
$person->age = '20';
$person->load();
$data = array('name' => 'Laure-Ashley', 'age' => '21', 'citizenship' => 'french');
$person->bind($data);
$person->update();
//Supprimer un user par l'id
$person = new Person();
$person->id = '611';
$person->remove();
Example #23
0
 public function testDeleteBypassTrash()
 {
     // Cleanup
     Person::deleteAll();
     // Insert
     $person = new Person();
     $person->first_name = 'John';
     $person->last_name = 'Doe';
     $person->email = '*****@*****.**';
     $person->post_title = 'John Doe';
     $post_id = $person->save();
     // Delete to trash
     $person = new Person();
     $this->assertTrue($person->load($post_id));
     $this->assertTrue(is_object($person->delete(true)));
     // Load shouldn't work
     $person = new Person();
     $this->assertFalse($person->load($post_id));
 }
Example #24
0
function person_permissions(&$user, $action, $arg1 = NULL, $arg2 = NULL)
{
    $all_view_fields = array('name', 'gender', 'willing_to_volunteer');
    if (variable_get('dog_questions', 1)) {
        $all_view_fields[] = 'dog';
    }
    $restricted_contact_fields = array('email', 'home_phone', 'work_phone', 'mobile_phone');
    $captain_view_fields = array('height', 'skill', 'shirtsize');
    $self_edit_fields = array_merge($all_view_fields, $captain_view_fields, $restricted_contact_fields, array('birthdate', 'address', 'height', 'shirtsize'));
    $create_fields = array_merge($self_edit_fields, array('username'));
    $self_view_fields = array('username', 'birthdate', 'address', 'last_login', 'member_id', 'height', 'shirtsize');
    $self_view_fields = array_merge($all_view_fields, $restricted_contact_fields, $self_view_fields);
    switch ($action) {
        case 'create':
            return true;
            break;
        case 'edit':
            if ('new' == $arg1) {
                // Almost all fields can be edited for new players
                if ($arg2) {
                    return in_array($arg2, $create_fields);
                } else {
                    return true;
                }
            }
            if (!$user || !$user->is_active()) {
                return false;
            }
            if ($user->user_id == $arg1) {
                if ($arg2) {
                    return in_array($arg2, $self_edit_fields);
                } else {
                    return true;
                }
            }
            break;
        case 'password_change':
            // User can change own password
            if (is_numeric($arg1)) {
                if ($user->user_id == $arg1) {
                    return true;
                }
            }
            break;
        case 'view':
            if (!($user && $user->is_active())) {
                return false;
            }
            if (is_numeric($arg1)) {
                if ($user->user_id == $arg1) {
                    // Viewing yourself allowed, most fields
                    if ($arg2) {
                        return in_array($arg2, $self_view_fields);
                    } else {
                        return true;
                    }
                } elseif (!$user->is_player()) {
                    // Name only
                    if ($arg2) {
                        return in_array($arg2, array('name'));
                    } else {
                        return true;
                    }
                } else {
                    // Other user.  Now comes the hard part
                    $player = Person::load(array('user_id' => $arg1));
                    // New or locked players cannot be viewed.
                    if ($player->status == 'new' || $player->status == 'locked') {
                        return false;
                    }
                    $sess_user_teams = implode(",", array_keys($user->teams));
                    $viewable_fields = $all_view_fields;
                    /* If player is a captain, their email is viewable */
                    if ($player->is_a_captain) {
                        // Plus, can view email
                        $viewable_fields[] = 'email';
                    }
                    if ($user->is_a_captain) {
                        /* If the current user is a team captain, and the requested user is on
                         * their team, they are allowed to view email/phone
                         */
                        foreach ($player->teams as $team) {
                            if ($user->is_captain_of($team->team_id) && $team->position != 'captain_request') {
                                /* They are, so publish email and phone */
                                $viewable_fields = array_merge($all_view_fields, $restricted_contact_fields, $captain_view_fields);
                                break;
                            }
                        }
                        /* If the current user is a team captain, and the requested user is
                         * captain for a "nearby" team, they are allowed to view email/phone
                         */
                        if ($player->is_a_captain) {
                            foreach ($player->teams as $player_team) {
                                if ($player->is_captain_of($player_team->team_id)) {
                                    foreach ($user->teams as $user_team) {
                                        if ($user->is_captain_of($user_team->team_id) && $player_team->league_id == $user_team->league_id) {
                                            $viewable_fields = array_merge($all_view_fields, $restricted_contact_fields);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    /* Coordinator info is viewable */
                    if ($player->is_a_coordinator) {
                        $viewable_fields = array_merge($all_view_fields, $restricted_contact_fields);
                    }
                    /* Coordinators get to see phone numbers of the captains they handle */
                    if ($user->is_a_coordinator && $player->is_a_captain) {
                        foreach ($player->teams as $team) {
                            if ($player->is_captain_of($team->team_id) && $user->coordinates_league_containing($team->team_id)) {
                                $viewable_fields = array_merge($all_view_fields, $restricted_contact_fields);
                            }
                        }
                    }
                    // Finally, perform the check and return
                    if ($arg2) {
                        return in_array($arg2, $viewable_fields);
                    } else {
                        return true;
                    }
                }
            }
            break;
        case 'list':
        case 'search':
            if (!($user && $user->is_active())) {
                return false;
            }
            if ($arg1) {
                // Specific searches require admin access
                return false;
            }
            return $user->class != 'visitor';
        case 'approve':
            // administrator-only
        // administrator-only
        case 'delete':
            // administrator-only
        // administrator-only
        case 'listnew':
            // administrator-only
        // administrator-only
        default:
            return false;
    }
    return false;
}
Example #25
0
<?php

//
require_once 'common.php';
//
$id = 1;
//
$name = Person::load($id, 'surname');
//
var_dump($name);
Example #26
0
 public function getEmail($_person_id = '', $_company_id = '')
 {
     /*
      * We only want to override the function parameters if the call has come from
      * an ajax request, simply overwriting them as we were leads to a mix up in
      * values
      */
     if (isset($this->_data['person_id'])) {
         if (!empty($this->_data['person_id'])) {
             $_person_id = $this->_data['person_id'];
         }
         if (!empty($this->_data['company_id'])) {
             $_company_id = $this->_data['company_id'];
         }
     }
     // Used by Ajax to return the person's email address
     // If no person is supplied, or they have no email address
     // look for the company technical email address
     // if still no email address is found, use the logged in user details
     $person = new Person();
     $email = '';
     if (!empty($_person_id)) {
         $person->load($_person_id);
         if ($person->isLoaded() && !is_null($person->email->contactmethod)) {
             $email = $person->email->contactmethod;
         }
     }
     if (empty($email) && !empty($_company_id)) {
         $email = Ticket::getCompanyEmail($_company_id);
     }
     if (empty($email)) {
         $user = getCurrentUser();
         if ($user) {
             $email = $user->email;
             if (!is_null($user->person_id)) {
                 $person->load($user->person_id);
                 if ($person->isLoaded() && !is_null($person->email->contactmethod)) {
                     $email = $person->email->contactmethod;
                 }
             }
         }
     }
     if (isset($this->_data['ajax'])) {
         $this->view->set('value', $email);
         $this->setTemplateName('text_inner');
     } else {
         return $email;
     }
 }
 function entered_by_name()
 {
     if (!$this->entered_by_user) {
         $this->entered_by_user = Person::load(array('user_id' => $this->entered_by));
     }
     return $this->entered_by_user->fullname;
 }
$course->save();
$s->addCourses($course);
$p = new Person();
$p->setCity($c);
$p->setEmail('*****@*****.**');
$p->setName('Other Person');
$p->save();
$b = new Book();
$b->setAuthor($p);
$b->setTitle('PHP Book');
$b->save();
Hypersistence::commit();
//LOAD
$p = new Person();
$p->setId(1);
$p->load();
echo $p->getName() . "\n";
$books = $p->getBooks()->execute();
foreach ($books as $b) {
    echo $b->getTitle() . "\n";
}
$s = new Student();
$s->setId(1);
$s->load();
echo $s->getName() . "\n";
$courses = $s->getCourses();
foreach ($courses as $c) {
    echo $c->getDescription() . "\n";
    $course = $c;
}
$s->deleteCourses($course);
Example #29
0
<?php

//
require_once 'common.php';
/*
 *  Update database record without load by id
\*/
// ---------
// WRONG WAY
// ---------
//
echo '<h2>WRONG WAY</h2>';
//
$Id = 1;
//
$Item = Person::load($Id);
//
$Item->age = 31;
//
$Item->store();
// ---------
// RIGHT WAY
// ---------
//
echo '<h2>RIGHT WAY</h2>';
//
$Id = 1;
//
Person::update($Id, array('age' => 31));
Example #30
0
 function get_captains()
 {
     global $dbh;
     $sth = $dbh->prepare("SELECT user_id\n\t\t\t\t\tFROM person p\n\t\t\t\t\t\tLEFT JOIN teamroster r ON p.user_id = r.player_id\n\t\t\t\t\tWHERE r.team_id IN (?,?)\n\t\t\t\t\t\tAND r.status IN ( 'captain', 'assistant', 'coach')");
     $sth->execute(array($this->home_id, $this->away_id));
     $captains = array();
     while ($user = $sth->fetch(PDO::FETCH_OBJ)) {
         $captains[] = Person::load(array('user_id' => $user->user_id));
     }
     return $captains;
 }