All pastes #247825 Raw Edit

Someone

public php v1 · immutable
#247825 ·published 2006-11-13 22:21 UTC
rendered paste body
*****************************main function*****************************function al_account_edit_next_contact_form($form_id, $form_values) {  $nid = $form_values['NextContactID'] ? $form_values['NextContactID'] : db_next_id('nextcontact_nid');  $conditions = array('NextContactID:d' => $nid);  $values = array(    'MasterID:d' => $form_values['MasterID'],    'NextContactDate:s' => $form_values['NextContactDate'],    'Action:s' => $form_values['Action'],    'Priority:d' => $form_values['Priority'],    'Person:s' => $form_values['Person'],    'Note:s' => $form_values['Note'],    'Comments:s' => $form_values['Comments'],    'Stage:s' => $form_values['Stage'],  );  if ($form_values['NextContactID']) {    al_update_query('nextcontact', $values, $conditions);  }  else {    $values = array_merge($values, $conditions);    al_insert_query('nextcontact', $values);  }  drupal_set_message(t('Next contact added successfully.'));  cache_clear_all($form_values['MasterID'], 'cache_al');  drupal_goto("al_account_edit/{$form_values['MasterID']}");}****************************************query helper functions****************************************function al_update_query($table, $values, $conditions) {  $columns = array();  foreach ($values as $key => $value) {  	$column = explode(':', $key);  	$sub = $column[1] == 'd' ? '%d' : "'%s'";  	$columns[] = $column[0] .' = '. $sub;  }  foreach ($conditions as $key => $value) {    $condition = explode(':', $key);    $sub = $condition[1] == 'd' ? '%d' : "'%s'";  	$where[] = $condition[0] .' = '. $sub;  	$values[] = $value;  }  al_query("UPDATE $table SET ". implode(',', $columns) .' WHERE '. implode(' AND ', $where), $values);}function al_insert_query($table, $values) {  $columns = array();  $vals = array();  foreach ($values as $key => $value) {  	$column = explode(':', $key);  	$columns[] = $column[0];  	$vals[] = $column[1] == 'd' ? '%d' : "'%s'";;  }  al_query("INSERT INTO $table (". implode(',', $columns) .') VALUES ('. implode(', ', $vals) .')', $values);}