function dev_db_update($table, $data, $where, $ignore_null = 0, &$query_str) { //echo 'updating, '; $updates = array(); $temp_values = array(); $update_string = ''; $query_str; foreach ($data as $a) { array_push($temp_values, dev_prep_input($a)); } $count = 0; foreach (array_keys($data) as $a) { //convert into query string if ($ignore_null == 1) { $temp_values[$count] = dev_ignore_null_entry($table, $a, $temp_values[$count], $where); } array_push($updates, "{$a} = {$temp_values[$count]}"); $count++; } $update_string = implode(', ', $updates); $query = "UPDATE `{$table}` SET {$update_string} WHERE {$where}"; //echo "$query<br />"; $query_str = $query; mysql_query($query) ? $status = true : ($status = false); return $status; }
function dev_draw_form_field($type = '', $name = '', $label = '', $value = '', $required = false, $id = '', $readonly = false, $properties = '') { $output = ''; $label_text = ''; $varname = $name; $properties = dev_value_to_array($properties); if (!isset($properties['class'])) { $properties['class'] = $type ? $type : 'formdata'; } foreach ($properties as $a => $b) { $attribs[] = "{$a}=\"{$b}\""; } $attrib = implode(' ', $attribs); $id = 'id="' . ($id != '' ? $id : $name) . '"'; $disabled = $readonly === false ? '' : 'readonly'; if ($readonly == 3) { $type = 'static'; } if ($label != '' && $type != 'static') { $label_text = '<label for="' . $name . '">' . ($required ? '*' : '') . $label . ': </label>'; } if ($type != 'date' && $type != 'select') { $name .= is_array($value) ? '[]' : ''; } $value = dev_value_to_array($value, true); switch ($type) { default: case 'text': foreach ($value as $a) { $output .= $label_text . ' <br />' . "\n\t" . '<input type="text" ' . $disabled . ' name="' . $name . '" ' . $id . ' value="' . $a . '" ' . $attrib . ' /><br />'; } break; case 'prompt': foreach ($value as $a) { $output .= $label_text . ' <br />' . "\n\t" . '<input type="text" ' . $disabled . ' name="' . $name . '" ' . $id . ' value="' . $a . '" ' . $attrib . ' onFocus="this.value=\'\'" /><br />'; } break; case 'password': foreach ($value as $a) { $output .= $label_text . ' <br />' . "\n\t" . '<input type="password" ' . $disabled . ' name="' . $name . '" ' . $id . ' value="' . $a . '" ' . $attrib . ' /><br />'; } break; case 'textarea': foreach ($value as $a) { $output .= $label_text . ' <br />' . "\n\t" . '<textarea ' . $disabled . ' name="' . $name . '" ' . $id . ' ' . $attrib . '>' . $a . '</textarea><br />'; } break; case 'select': $output .= $label_text . ' <br />' . "\n"; $output .= '<select name="' . $name . '" ' . $disabled . ' ' . $id . ' ' . $attrib . '>' . "\n"; $value = dev_value_to_array($value); global ${$varname}; foreach ($value as $a => $b) { if (is_array($b)) { $output .= "\t" . '<optgroup label="' . $a . '">' . "\n"; foreach ($b as $c => $d) { $output .= "\t\t" . '<option value="' . $d . '"'; //if the select option being drawn is the same as the //variable by the same name of this element, mark it as selected if (${$varname} == $d) { $output .= ' selected="selected"'; } $output .= '>' . $c . '</option>' . "\n"; } $output .= "\t" . '</optgroup>' . "\n"; } else { $output .= "\t" . '<option value="' . $b . '"'; //if the select option being drawn is the same as the //variable by the same name of this element, mark it as selected if (${$varname} == $b) { $output .= ' selected="selected"'; } $output .= '>' . $a . '</option>' . "\n"; } } $output .= '</select><br />'; break; case 'multiple': $output .= $label_text . ' <br />' . "\n"; $output .= '<select name="' . $name . '" ' . $disabled . ' ' . $id . ' ' . $attrib . ' size="6" multiple="multiple">' . "\n"; $value = dev_value_to_array($value); global ${$varname}; foreach ($value as $a => $b) { if (is_array($b)) { $output .= "\t" . '<optgroup label="' . $a . '">' . "\n"; foreach ($b as $c => $d) { $output .= "\t\t" . '<option value="' . $d . '"'; //if the select option being drawn is the same as the //variable by the same name of this element, mark it as selected if (is_array(${$varname})) { if (in_array($d, ${$varname})) { $output .= ' selected="selected"'; } elseif (${$varname} == $d) { $output .= ' selected="selected"'; } } $output .= '>' . $c . '</option>' . "\n"; } $output .= "\t" . '</optgroup>' . "\n"; } else { $output .= "\t" . '<option value="' . $b . '"'; //if the select option being drawn is the same as the //variable by the same name of this element, mark it as selected if (is_array(${$varname})) { if (in_array($b, ${$varname})) { $output .= ' selected="selected"'; } elseif (${$varname} == $b) { $output .= ' selected="selected"'; } } $output .= '>' . $a . '</option>' . "\n"; } } $output .= '</select><br />'; break; case 'hidden': foreach ($value as $a) { $output .= '<input type="hidden" ' . $disabled . ' name="' . $name . '" ' . $id . ' value="' . $a . '" />'; } break; case 'checkbox': if (dev_is_assoc($value)) { $output .= ($required ? '*' : '') . $label . '<br />'; $i = 1; foreach ($value as $a => $b) { $output .= '<input ' . $attrib . ' type="checkbox" ' . $disabled . ' name="' . $name . '" ' . substr_replace($id, $i . '"', -1, strlen($id)); global ${$varname}; if (${$varname} == $b) { $output .= ' checked="checked"'; } $output .= ' value="' . $b . '" />'; $output .= '<label for="' . $varname . $i . '">' . substr($a, 0, strlen($a)) . " </label><br /> \n"; $i++; } } else { foreach ($value as $a) { $output .= '<input type="checkbox" ' . $disabled . ' name="' . $name . '" ' . $id; global ${$varname}; if (${$varname} == $a) { $output .= ' checked="checked"'; } $output .= ' value="' . $a . '" /> '; $output .= '<label for="' . $varname . '">' . substr($label, 0, strlen($label)) . " </label><br /> \n"; } } break; case 'radio': if (dev_is_assoc($value)) { $output .= ($required ? '*' : '') . $label . '<br />'; $i = 1; foreach ($value as $a => $b) { $output .= '<input ' . $attrib . ' type="radio" ' . $disabled . ' name="' . $name . '" ' . substr_replace($id, $i . '"', -1, strlen($id)); global ${$varname}; if (${$varname} == $b) { $output .= ' checked="checked"'; } $output .= ' value="' . $b . '" />'; $output .= '<label for="' . $varname . $i . '">' . substr($a, 0, strlen($a)) . " </label><br /> \n"; $i++; } } else { foreach ($value as $a) { $output .= '<input type="radio" ' . $disabled . ' name="' . $name . '" ' . $id; global ${$varname}; if (${$varname} == $a) { $output .= ' checked="checked"'; } $output .= ' value="' . $a . '" /> '; $output .= '<label for="' . $varname . '">' . substr($label, 0, strlen($label)) . " </label><br /> \n"; } } break; case 'date': $output .= dev_draw_date_select($name, $label, $value[0], $readonly); break; case 'calendar': $output .= $label_text . "\n\t" . '<SCRIPT LANGUAGE="JavaScript" ID="js' . $name . '"> var cal' . $name . ' = new CalendarPopup("datediv1"); cal' . $name . '.setCssPrefix("DATE"); </SCRIPT> <SCRIPT LANGUAGE="JavaScript">writeSource("js' . $name . '");</SCRIPT> <input type="text" ' . $disabled . ' name="' . $name . '" ' . $id . ' value="' . $value[0] . '" ' . $attrib . ' /> <A HREF="#" onclick="cal' . $name . '.select(document.getElementById(\'' . $name . '\'),\'anchor' . $name . '\',\'yyyy-MM-dd\'); return false;" TITLE="cal' . $name . '.select(document.getElementById(\'' . $id . '\'),\'anchor1x\',\'yyyy-MM-dd\'); return false;" NAME="anchor' . $name . '" ID="anchor' . $name . '"><img src="' . $image_path . 'calendar.gif" alt="select" title="select" border="0" /></A><br />'; break; case 'time': $output .= dev_draw_time_select($name, $label); break; case 'file': foreach ($value as $a) { if (!$readonly && $a == '') { $output .= $label_text . ' - ' . $a . ' <br />' . "\n\t" . '<input type="file" ' . $disabled . ' name="' . $name . '" ' . $id . ' /><br />'; } else { $output = dev_draw_form_field('checkbox', $name, $label . ' (' . $a . ')', $a, $required, $name, $readonly, $properties); } } break; case 'richtext': foreach ($value as $a) { //Code provided by Kevin Roth at www.kevinroth.com/rte/demo.htm //Requires following form header: /* <script language="JavaScript" type="text/javascript"> <!-- function submitForm() { //make sure hidden and iframe values are in sync before submitting form //to sync only 1 rte, use updateRTE(rte) //to sync all rtes, use updateRTEs //updateRTE(\'rte1\'); updateRTEs(); //change the following line to true to submit form return true; } //Usage: initRTE(imagesPath, includesPath, cssFile, genXHTML) initRTE("images/", "", "", true); //--> </script> */ //and included JS file and 'onsubmit="return submitForm();"' in form. $output .= ' <noscript>'; $output .= dev_draw_form_field('textarea', $name, $label, $a, '', $id, $readonly); $output .= ' </noscript> <script language="JavaScript" type="text/javascript"> <!-- var ' . $name . '_val = ""; '; //$output .= "\n"; $a = html_entity_decode($a); $val_search = array('"', '</script>', '</textarea>', '</noscript>'); $val_replace = array('\\"', '</script>', '</textarea>', '</noscript>'); $a = str_replace($val_search, $val_replace, $a); $val_array = explode("\n", $a); //foreach ($val_array as $a) $output .= $name . '_val += "' . html_entity_decode(rtrim($a)) . '\n";' . "\n"; foreach ($val_array as $var) { $output .= $name . '_val += "' . rtrim($var) . '\\n";' . "\n"; } $output .= ' //--> </script> '; //$output .= dev_draw_form_field('hidden', $name . '_hidden', '', $a); if ($id == 'id="big"') { $w = '100%'; $h = 400; } else { $w = 450; $h = 200; } $output .= ' <script language="JavaScript" type="text/javascript"> <!-- ' . $name . '_val = ' . $name . '_val.replace(/<\\/script>/gi, "<" + "/script>"); ' . $name . '_val = ' . $name . '_val.replace(/<\\/textarea>/gi, "<" + "/textarea>"); ' . $name . '_val = ' . $name . '_val.replace(/<\\/noscript>/gi, "<" + "/noscript>"); writeRichText(\'' . $name . '\', ' . $name . '_val, \'' . $w . '\', \'' . $h . '\', true, ' . ($readonly ? 'true' : 'false') . '); //--> </script> '; } break; case 'static': foreach ($value as $a) { $output .= $label . '<br /><span ' . implode(' ', $attribs) . ' name="' . $name . '" ' . $id . '>' . $a . '</span>'; $output .= dev_draw_form_field('hidden', $name, '', $a); } break; case 'submit': foreach ($value as $a) { $output .= '<input type="submit" ' . $disabled . ' name="' . $name . '" ' . $id . ' value="' . $a . '" onclick="this.disabled=false;this.value=' . dev_prep_input($label != '' ? $label : 'Submitting...') . ';" ' . $attrib . ' /><br />'; } break; case 'reset': foreach ($value as $a) { $output .= '<input type="reset" ' . $disabled . ' name="' . $name . '" ' . $id . ' value="' . $a . '" ' . $attrib . ' /><br />'; } break; case 'button': foreach ($value as $a) { $output .= '<input type="button" ' . $disabled . ' name="' . $name . '" ' . $id . ' value="' . $a . '" ' . $attrib . ' /><br />'; } break; } if ($label != '' && $type != 'hidden') { $output .= "<br />\n"; } return $output; }
function createWhereCase($table = '', $member, $value = '') { $table = dev_is_null($table) ? $this->getReferenceTable() : $table; $where = ''; $where_r = array(); $condition = $this->getCondition($member); $condition_str = is_array($condition) ? $condition[0] : $condition; if (dev_not_empty($this->getField($member))) { //Allow for fulltext searches if (strtoupper($condition_str) == 'MATCH') { $match_var = $this->getConditionKey($member); if (strpos($match_var, ',')) { $match_r = explode(',', $match_var); foreach ($match_r as $c => $d) { $match_r[$c] = "{$table}." . trim($d); } $match_str = implode(', ', $match_r); } elseif (array_key_exists($member, $this->_conditional_vars)) { $match_str = "{$table}.{$member}"; } if (is_array($value)) { foreach ($value as $a) { if (dev_not_null($a)) { $where_r[] = "MATCH({$match_str}) AGAINST (" . dev_prep_input($a) . ")"; } } $where = implode(' OR ', $where_r); } else { $where = "MATCH({$match_str}) AGAINST (" . dev_prep_input($value) . ")"; } } elseif (strtoupper($condition_str) == 'IN') { if (is_array($value)) { foreach ($value as $a) { if (dev_not_null($a)) { $where_r[] = $table . ".{$member} " . (array_key_exists($member, $this->_conditional_vars) ? "{$condition} " : "= ") . $a; } $where = implode(' OR ', $where_r); } } else { $where = $table . ".{$member} " . (array_key_exists($member, $this->_conditional_vars) ? $condition : " = ") . "( {$value} )"; } } elseif (strtoupper($condition_str) == 'NOT IN') { if (is_array($value)) { foreach ($value as $a) { if (dev_not_null($a)) { $where_r[] = $table . ".{$member} " . (array_key_exists($member, $this->_conditional_vars) ? "{$condition} " : "= ") . $a; } $where = implode(' OR ', $where_r); } } else { $where = $table . ".{$member} " . (array_key_exists($member, $this->_conditional_vars) ? $condition : " = ") . "( {$value} )"; } } else { if (is_array($value)) { $count = 0; foreach ($value as $a) { if (dev_not_null($a)) { $temp_where = ''; $temp_where = $table . ".{$member} " . (array_key_exists($member, $this->_conditional_vars) ? is_array($condition) ? $condition[$count] : $condition : " = "); if ($condition_str == 'Like') { $a = "{$a}%"; } elseif ($condition_str == 'likE') { $a = "%{$a}"; } elseif (strtoupper($condition_str) == 'LIKE') { $a = "%{$a}%"; } $temp_where .= dev_prep_input($a); $where_r[] = $temp_where; $count++; } } $where = implode(is_array($condition) ? ' AND ' : ' OR ', $where_r); } else { $where = $table . ".{$member} " . (array_key_exists($member, $this->_conditional_vars) ? $condition : " = "); if ($condition_str == 'Like') { $value = "{$value}%"; } elseif ($condition_str == 'likE') { $value = "%{$value}"; } elseif (strtoupper($condition_str) == 'LIKE') { $value = "%{$value}%"; } $where .= dev_prep_input($value); } } //$where_r[] = $where; if (dev_not_null($where)) { $where = "({$where}) "; } } return $where; }