Example #1
0
 function performDBquery()
 {
     /* Making MySQL query */
     // Getting fields and values
     $fields = array();
     foreach ($this->vars as $var) {
         if ($var['DBQueryPerform']) {
             if ($var['type'] == 'checkbox') {
                 // Splittalize?
                 $fields[$var['var']] = splittalize($var['value_array']);
             } else {
                 $fields[$var['var']] = $var['value'];
             }
         }
     }
     if ($this->db_field_edit != '') {
         $fields[$this->db_field_edit] = time();
     }
     if ($this->db_field_edit_by != '') {
         $fields[$this->db_field_edit_by] = $this->db_field_edit_by_value;
     }
     // Edit or add?
     $SQL = '';
     if ($this->id != '') {
         // Edit
         $SQL = "UPDATE `" . $this->db_table . "` SET ";
         $i = 0;
         foreach ($fields as $field => $value) {
             $i++;
             $SQL .= "`{$field}` = '" . $value . "'";
             if ($i < count($fields)) {
                 $SQL .= ', ';
             }
         }
         if (is_array($this->id)) {
             // Composite PK
             $where = array();
             foreach ($this->db_field_id as $pk) {
                 $where[$pk] = '`' . $pk . '` = \'' . $this->id[$pk] . '\'';
             }
             $SQL .= ' WHERE ' . implode(' AND ', $where);
         } else {
             $SQL .= " WHERE `" . $this->db_field_id . "` = '" . $this->id . "'";
         }
         $SQL .= " LIMIT 1 ;";
         /* Running MySQL query */
         mysql_query($SQL);
         if (mysql_errno()) {
             return false;
         }
     } else {
         // Add
         $SQL .= 'INSERT INTO `' . $this->db_table . '` (';
         $i = 0;
         foreach ($fields as $field => $value) {
             $i++;
             $SQL .= "`{$field}`";
             if ($i < count($fields)) {
                 $SQL .= ',';
             }
         }
         $SQL .= ') VALUES (';
         $i = 0;
         foreach ($fields as $field => $value) {
             $i++;
             $SQL .= "'{$value}'";
             if ($i < count($fields)) {
                 $SQL .= ',';
             }
         }
         $SQL .= ');';
         /* Running MySQL query */
         mysql_query($SQL);
         if (mysql_errno()) {
             return false;
         }
         $this->id = mysql_insert_id();
     }
     return TRUE;
 }
     } else {
         $SQL .= "`{$change}` = '" . ${$change} . "'";
     }
     if (count($changed) != $i) {
         $SQL .= ', ' . chr(10);
     }
 }
 $SQL .= " WHERE `entry`.`entry_id` ={$entry_id} LIMIT 1 ;";
 mysql_query($SQL);
 // # Log
 // Generating $log_data
 $only_invoice_changed = true;
 $log_data = array();
 foreach ($changed2 as $change) {
     if ($change == 'user_assigned' || $change == 'room_id') {
         $log_data[$change] = splittalize(${$change});
     } elseif ($change == "customer_municipal") {
         // Ignore
     } else {
         $log_data[$change] = ${$change};
     }
     // Only invoice changes?
     if (substr($change, 0, 7) != 'invoice') {
         $only_invoice_changed = false;
     }
 }
 if (!newEntryLog($entry_id, 'edit', '', $rev_num, $log_data)) {
     echo __('Can\'t log the changes for the entry.');
     exit;
 }
 // iCal
Example #3
0
    // Undelete
    $from_table = 'entry_deleted';
    $to_table = 'entry';
    $log_action2 = 'entry_undeleted';
}
mysql_query('insert into ' . $to_table . ' (select * from ' . $from_table . ' where `entry_id` = \'' . $entry['entry_id'] . '\' limit 1)');
if (mysql_error()) {
    emailSendAdmin('Problems in entry_delete', 'Mysql error on insert query:' . chr(10) . mysql_error() . chr(10));
    echo 'En feil oppsto. Feilmelding er sendt til systemadministrator.<br />';
    echo 'Sletting vil ikke være tilgjengelig før dette er fikset.';
    exit;
}
// Building log_data
$log_data = $entry;
$log_data['room_id'] = splittalize($log_data['room_id']);
$log_data['user_assigned'] = splittalize($log_data['user_assigned']);
unset($log_data['contact_person_email2']);
unset($log_data['mva']);
unset($log_data['mva_grunnlag']);
unset($log_data['mva_grunnlag_sum']);
unset($log_data['faktura_belop_sum']);
unset($log_data['faktura_belop_sum_mva']);
unset($log_data['eks_mva_tot']);
unset($log_data['grunnlag_mva_tot']);
unset($log_data['mva_vis']);
unset($log_data['customer_name']);
unset($log_data['time_day']);
unset($log_data['time_month']);
unset($log_data['time_year']);
unset($log_data['time_hour']);
unset($log_data['time_min']);
Example #4
0
 function create($invoice_time_due, $invoice_time, $invoice_content, $invoice_extracontent = array())
 {
     if (!$this->doDaChecking($invoice_time_due, $invoice_time, $invoice_content, $invoice_extracontent)) {
         return FALSE;
     }
     // Serialize
     $this->invoice_content = serialize($this->invoice_content);
     $this->invoice_idlinks = splittalize($this->invoice_idlinks);
     /* ### SQL, inndata sjekket ### */
     $SQL = "INSERT INTO `invoice` \n\t\t\t(";
     $i = 0;
     foreach ($this->insert_this as $denne) {
         $i++;
         $SQL .= "`{$denne}`";
         if (count($this->insert_this) != $i) {
             $SQL .= ' , ';
         }
     }
     $SQL .= ")\n\t\tVALUES (";
     $i = 0;
     $this->log_data = array();
     foreach ($this->insert_this as $denne) {
         $i++;
         $value = $this->{$denne};
         $SQL .= "'" . $value . "'";
         if (count($this->insert_this) != $i) {
             $SQL .= ' , ';
         }
         $this->log_data[$denne] = $value;
     }
     $SQL .= ");";
     mysql_query($SQL);
     if (mysql_error()) {
         $this->error_code = '1';
         return FALSE;
     }
     $this->invoice_id = mysql_insert_id();
     newInvoiceLog($this->invoice_id, 'add', '', 1, $this->log_data);
     $this->invoice_content = unserialize($this->invoice_content);
     $this->invoice_idlinks = splittString($this->invoice_idlinks);
     $this->updateNonDBFields();
     $this->createPDF();
     /* Linked to any entries? */
     foreach ($this->invoice_idlinks as $link) {
         list($idtype, $id) = explode('=', $link);
         switch ($idtype) {
             case 'e':
                 // Entry
                 $entry = getEntry($id);
                 if (count($entry)) {
                     /*
                      * Set new status
                      * Set new rev_num, time of edit, etc
                      */
                     $rev_num = $entry['rev_num'] + 1;
                     mysql_query("UPDATE `entry` SET `invoice_status` = '3', `user_last_edit` = '" . $this->invoice_created_by_id . "', `time_last_edit` = '" . time() . "', `rev_num` = '{$rev_num}' WHERE `entry_id` = '" . $entry['entry_id'] . "' LIMIT 1 ;");
                     $log_data = array();
                     if (!newEntryLog($entry['entry_id'], 'edit', 'invoice_made', $rev_num, $log_data)) {
                     }
                 }
                 break;
             default:
                 // Do nothing
                 break;
         }
     }
     $this->getCreatedBy();
     return TRUE;
 }