示例#1
0
 function set($var, $value)
 {
     $value = mydb::cxn()->real_escape_string($value);
     switch ($var) {
         case 'serial_num':
             // The Serial Number of an item is not restricted to any subset of characters. Any string is allowed, provided that it fits into the allowed VARCHAR space in the database
             if ($this->is_duplicate($value)) {
                 throw new Exception('That serial number (' . strtoupper($value) . ') is already being used for an item of type \'' . $this->item_type . '\'');
             } else {
                 $this->serial_num = $value;
             }
             break;
         case 'item_type':
             $this->item_type = $value;
             break;
         case 'color':
             $this->color = $value;
             break;
         case 'size':
             $this->size = $value;
             break;
         case 'description':
             $this->description = $value;
             break;
         case 'condition':
             $this->condition = $value;
             break;
         case 'note':
             $this->note = $value;
             break;
         case 'crew_affiliation_id':
             if (!is_numeric($value) || !(intval($value) == floatval($value))) {
                 throw new Exception('A non-integer Crew ID was passed to item->set().');
             } else {
                 if (!crew::exists($value)) {
                     throw new Exception('The Item cannot be affiliated with Crew #' . $value . ' because that Crew does not exist.');
                 } else {
                     $this->crew_affiliation_id = $value;
                     $this->crew_affiliation_name = crew::get_name($value);
                 }
             }
             break;
         case 'status':
             if (in_array(strtolower($value), $this->valid_status)) {
                 $this->status = strtolower($value);
             } else {
                 throw new Exception('The item->set() function attempted to set an invalid \'status\' (' . $value . ')');
             }
             break;
         default:
             throw new Exception('The item->set() function attempted to modify an invalid variable (' . $var . ')');
             break;
     }
     // End: switch($var)
 }