function format() { $fdata = $this->data; if (!isset($fdata['nid'])) { $fdata['nid'] = ''; } $fdata['description'] = mask_html($fdata['description']); $fdata['birthday'] = date_input('data[birthday_arr]', $fdata['birthday']); for ($i = 0; $i < strlen($this->opt_str); $i++) { $fdata['opt' . $i] = array(); if ($this->opt_str[$i]) { $fdata['opt' . $i][] = array(); } } $fdata['pic'] = $this->picture(); $this->fdata = $fdata; }
/** * Create a XHTML form for plugin attribute * * @author Alessandro De Zorzi <*****@*****.**> * * @param string $p_name The plugin name * @param array $attributes The attributes * @return mixed **/ function form_template($p_name, $attributes, $myvalues, $skip_table = null) { global $action; global $minAuthLevel; global $domain; $dn_domain = 'vd=' . $domain . ',' . LDAP_BASE; $domain_values = PhammLdap::phamm_self_values($dn_domain, $filter = "(objectClass=*)"); $tag = ''; if (!isset($skip_table)) { $tag .= '<table class="">'; } if (is_array($attributes)) { foreach ($attributes as $key => $attr) { if (!isset($hidden)) { $tag .= '<tr><td>'; } // Set attributes $name = strtolower($key); $hidden = isset($attr["HIDDEN"]) ? 'type="hidden"' : null; $minAuthLevel = isset($attr["MINAUTHLEVEL"]) ? $attr["MINAUTHLEVEL"] : 0; $size = isset($attr["SIZE"]) && !isset($attr["HIDDEN"]) ? 'size="' . $attr["SIZE"] . '"' : null; $disabled = isset($attr["DISABLED"]) ? 'disabled="disabled"' : null; $maxlength = isset($attr["MAXLENGHT"]) ? strtolower($attr["MAXLENGTH"]) : null; $subordinated = isset($attr["SUBORDINATED"]) ? strtoupper($attr["SUBORDINATED"]) : null; $subordinatedreverse = isset($attr["SUBORDINATEDREVERSE"]) ? strtoupper($attr["SUBORDINATEDREVERSE"]) : null; $max_key = strtolower('max' . $key); if (isset($domain_values[0][$max_key][0])) { // Disable value is possible only from TRUE to FALSE if (isset($myvalues[0][$name][0]) || $myvalues[0][$name][0] == 'FALSE') { $max_val = $domain_values[0][$max_key][0]; // For Bool attrbute only check the sum of total account with attribute set TRUE if ($attr["BOOL"] == 1) { $active_val = PhammLdap::phamm_self_values($dn_domain, '(&(objectClass=*)(' . $key . '=TRUE))'); $current_val_count = $active_val["count"]; } else { $active_val = PhammLdap::phamm_search('vd=' . $domain . ',' . LDAP_BASE, '(&(objectClass=VirtualMailAccount))', array($key)); $total_key = 0; foreach ($active_val as $one_val) { if ($one_val[$key][0]) { $total_key = $total_key + $one_val[$key][0]; } } // @todo if ('quota' == $key) { $total_key = $total_key / 1024 / 1024 - $active_val['count'] * 2000; } $current_val_count = $total_key; } if ($current_val_count >= $max_val) { phamm_print_message('info', sprintf(_("The maximum number of attribute %s (%s) has been reached or exceeded. Attribute has been disabled!"), $key, $max_val)); $disabled = 'disabled="disabled"'; } } } // Set XHTML Tags $required = isset($attr["REQUIRED"]) ? ' *' : null; // Set Default value $value = ''; // Set standard value if (isset($myvalues[$p_name][$name])) { $value = $myvalues[$p_name][$name]; } elseif (isset($myvalues[0][$name][0])) { // If attr is multiple if (isset($attr["MULTIPLE"])) { $value = $myvalues[0][$name]; } else { $value = $myvalues[0][$name][0]; } } // Multiplier (Ex. Quota x 1024) if (isset($attr["MULTIPLIER"]) && in_array($action, array('modify_account', 'domain_property'))) { $value = $value / $attr["MULTIPLIER"]; } elseif (isset($attr["DEFAULT"]) && ($action == 'add_account' || $action == 'add_domain')) { if (preg_match('/^=php\\.(\\w+)\\((.*)\\)$/', $attr["DEFAULT"], $matches)) { $args = preg_split('/,/', $matches[2]); $function_name = $matches[1]; switch ($function_name) { case "Value": foreach ($args as $arg) { // Global vars if (preg_match('/^%(\\w+)(\\|.+)?(\\/[lU])?%/U', $arg, $matches)) { $var_name = $matches[1]; global ${$var_name}; $value .= ${$var_name}; } elseif (preg_match('/^\\+(\\w+)(\\|.+)?(\\/[lU])?\\+/U', $arg, $matches)) { $var_name = $matches[1]; $value .= $_POST[$var_name]; } else { $value .= $arg; } } break; // Call PHP Function // Call PHP Function default: if (function_exists($function_name)) { // Escape a string to be used as a shell argument foreach ($args as $arg) { $args_escaped = escapeshellarg($arg); } $value = call_user_func_array($function_name, $args_escaped); } break; } } else { $value = $attr["DEFAULT"]; } } // Hide values if SUBORDINATED to another if (isset($attr["SUBORDINATED"])) { if (isset($myvalues[0][strtolower($subordinated)][0])) { $hidden = $myvalues[0][strtolower($subordinated)][0] == "TRUE" ? null : 1; } elseif (isset($myvalues[$p_name][strtolower($subordinated)])) { $hidden = $myvalues[$p_name][strtolower($subordinated)] == "TRUE" ? null : 1; } else { $hidden = 1; } } if (isset($attr["SUBORDINATEDREVERSE"])) { if (isset($myvalues[0][strtolower($subordinatedreverse)][0])) { $hidden = $myvalues[0][strtolower($subordinatedreverse)][0] == "FALSE" ? null : 1; } elseif (isset($myvalues[$p_name][strtolower($subordinatedreverse)])) { $hidden = $myvalues[$p_name][strtolower($subordinatedreverse)] == "FALSE" ? null : 1; } else { $hidden = 1; } } if (!isset($hidden)) { $label = isset($attr["PRETTYNAME"]) ? $attr["PRETTYNAME"] : $key; $tag .= gettext($label); $tag .= $required; $tag .= "</td><td>"; } if (isset($attr["BOOL"]) && !isset($hidden)) { $reverse = isset($attr["REVERSE"]) ? 1 : null; $tag .= trueorfalse("values[" . $p_name . "]", $value, $name, $reverse, $disabled); } elseif (isset($attr["OPTIONS"]) && !isset($hidden)) { if ($_SESSION["login"]["level"] < $minAuthLevel) { $tag .= $value; } else { $tag .= '<select class="form-control" name="values[' . $p_name . '][' . $name . ']">'; foreach ($attr["OPTIONS"] as $k => $v) { $label = isset($attr["PRETTYNAME"]) ? $attr["PRETTYNAME"] : $k; $label = $k; $selected = $value == $v["VALUE"] ? 'selected="selected"' : ''; $tag .= '<option value="' . $v["VALUE"] . '" ' . $selected . '>' . $label . ' (' . $v["VALUE"] . ')</option>' . "\n"; } $tag .= '</select>' . "\n\n"; } } elseif (isset($attr["DATE"]) && !isset($hidden)) { $current_date = $value ? $value : date('Y' . '-' . 'm' . '-' . 'd'); if ($_SESSION["login"]["level"] < $minAuthLevel) { $tag .= $value; } else { $tag .= date_input('values_date[' . $p_name . '][' . $name . ']', $current_date, $format = 'ymd'); } } elseif (isset($attr["TEXTAREA"]) && !isset($hidden)) { if ($_SESSION["login"]["level"] < $minAuthLevel) { $tag .= nl2br($value); } else { // Show box to add multiple values $tag .= '<textarea name="values[' . $p_name . '][' . $name . ']" cols="35" rows="5">'; $tag .= stripslashes($value); $tag .= "</textarea><br/>"; } } elseif (isset($attr["MULTIPLE"]) && !isset($hidden)) { // Show box to add multiple values $tag .= '<textarea name="values_multi[' . $p_name . '][' . $name . ']" cols="35" rows="5">'; if (isset($attr["TEXTAREA"])) { $tag .= stripslashes($value); } $tag .= "</textarea><br/>"; // Show the values if (is_array($value)) { for ($i = 0; $i < $value["count"]; $i++) { $tag .= '<input type="checkbox" name="values_multi_del[' . $p_name . '][' . $name . '][]" value="' . $value[$i] . '" />'; $tag .= $value[$i] . "<br/>"; } } } elseif (isset($attr["SUBORDINATEDDELETE"]) && $value) { $tag .= '<input type="checkbox" name="values_multi_del[' . $p_name . '][' . $name . ']" value="' . $value . '" id="subordinatedelete" />'; $tag .= $value . "<br/>"; } else { if (isset($hidden)) { $input_type = 'hidden'; } else { $input_type = 'text'; } // Show Value Only if auth level > level required if ($_SESSION["login"]["level"] >= $minAuthLevel) { $tag .= '<input type="' . $input_type . '" class="form-control" value="' . $value . '" name="values[' . $p_name . '][' . $name . ']" ' . $size . ' ' . $disabled . ' />'; } elseif (!isset($hidden)) { $tag .= $value; } } if (!isset($hidden)) { $tag .= "</td></tr>"; } } } // Exception, if last array attribute is hidden // XHTML Syntax required to close a TR if (isset($hidden)) { $tag .= "</td><td></td></tr>"; } if (!isset($skip_table)) { $tag .= "</table>"; } return $tag; }
$name = get_name($person); $title = "{$_Edit_event} #{$event} ({$_person} #{$person} {$name})"; require "./form_header.php"; echo "<h2>{$title}</h2>\n"; $rec = fetch_row_assoc("SELECT tag_fk, place_fk, event_date, date2text(sort_date) AS sd, event_note\n FROM events WHERE event_id = {$event}"); $note = note_from_db($rec['event_note']); $notelen = strlen($note); $notelen < 1000 ? $note_height = 5 : ($note_height = 20); $note_width = 100; form_begin('edit_event', $_SERVER['PHP_SELF']); hidden_input('person', $person); hidden_input('event', $event); hidden_input('posted', 1); select_tag($rec['tag_fk'], $person, $event); select_place($rec['place_fk']); date_input($rec['event_date'], $rec['sd']); textarea_input("{$_Text}:<br />{$notelen}", $note_height, $note_width, 'event_note', $note); source_input(); text_input("{$_Age}:", 10, 'age', '', "({$_Adds_birth_event})"); form_submit(); form_end(); echo "<h3>{$_Citations}</h3>\n"; $handle = pg_query("SELECT source_fk FROM event_citations WHERE event_fk = {$event}"); while ($row = pg_fetch_row($handle)) { echo '<p>' . $row[0] . ' '; echo fetch_val("SELECT get_source_text({$row['0']})"); echo "</p>\n"; } echo "</body>\n</html>\n"; } else { // do action
*/ include 'var.php'; require_once $root . 'class_DateTimeFormatter.php'; // formates data of a todolist function format_todolist($pid) { global $db; $db->select('id,name,deadline from todo where pid="' . $pid . '" order by deadline'); $fdata = array(); foreach ($db->data as $i => $a) { $dateTimeFormatter = new DateTimeFormatter($a['deadline']); $a['deadline'] = $dateTimeFormatter->toStringUrgent(); $fdata[] = $a; } return $fdata; } $output->secure(); $output->title[] = 'todolist'; $output->headline[] = 'todolist'; $_SESSION['origin'] = 'todolist.php'; $vars['entry'] = format_todolist($_SESSION['userid']); $vars['date'] = date_input('data', date('Y-m-d')); $vars['date_year'] = date('Y'); $vars['date_month'] = tmpl_select_int('data[month]', 1, 12, date('m'), '{Month}'); $vars['date_day'] = tmpl_select_int('data[day]', 1, 31, date('d'), '{Day}'); $vars['time_hour'] = tmpl_select_int('data[hour]', 0, 23, date('H'), '{Hour}'); $vars['time_minute'] = tmpl_select_int('data[minute]', 0, 59, 0, '{Minute}'); $vars['time_second'] = tmpl_select_int('data[second]', 0, 59, 0, '{Second}'); $vars['textarea'] = tmpl_textarea('data[text]'); $content = new tmpl('todolist.html', $vars); $output->out($content);
function datetime_input($name, $datetime = '0000-00-00 00:00:00') { list($date, $time) = explode(' ', $datetime); $v['name'] = $name; $v['date_input'] = date_input($name, $date); $v['time'] = $time; $tmpl = new tmpl('datetime_input.html', $v, $GLOBALS['root']); return $tmpl->fdata; }
if (!isset($_POST['posted'])) { // display form $note_height = 5; $note_width = 100; $person = $_GET['person']; $name = get_name($person); $title = "{$_Add_event_for} ({$person}) {$name}"; require "./form_header.php"; echo "<h2>{$title}</h2>\n"; form_begin('insert_event', $_SERVER['PHP_SELF']); hidden_input('posted', 1); hidden_input('person', $person); select_tag(0, 0, 0); participant_input(0); select_place(0); date_input(); textarea_input("{$_Text}:", $note_height, $note_width, 'event_note', '', 4); source_input(); text_input("{$_Age}:", 10, 'age', '', "({$_Adds_birth_event})", 7); form_submit(); form_end(); echo "</body>\n</html>\n"; } else { $src = $_POST['source_id']; $txt = $_POST['source_text']; if ($txt && fetch_val("SELECT is_leaf({$src})") == 't') { echo "Cannot create subsource under source #{$src}. "; echo "Please go back and check your source reference."; die; } // process form
function format() { $data =& $this->data; $fdata = $data; $month = substr($data['deadline'], 5, 2); $day = substr($data['deadline'], 8, 2); $hour = substr($data['deadline'], 11, 2); $minute = substr($data['deadline'], 14, 2); $second = substr($data['deadline'], 17, 2); $expire = array(); if (isset($data['expire']) && $data['expire']) { $expire[] = array(); } $fdata['created'] = local_datetime_title($data['created']); $fdata['deadline_date'] = date_input('data', $data['deadline']); $dateTimeFormatter = new DateTimeFormatter($data['deadline']); $fdata['deadline'] = $dateTimeFormatter->toStringUrgent(); $fdata['deadline_year'] = substr($data['deadline'], 0, 4); $fdata['deadline_month'] = tmpl_select_int('data[month]', 1, 12, $month, '{Month}'); $fdata['deadline_day'] = tmpl_select_int('data[day]', 1, 31, $day, '{Day}'); $fdata['deadline_hour'] = tmpl_select_int('data[hour]', 0, 23, $hour, '{Hour}'); $fdata['deadline_minute'] = tmpl_select_int('data[minute]', 0, 59, $minute, '{Minute}'); $fdata['deadline_second'] = tmpl_select_int('data[second]', 0, 59, $second, '{Second}'); $fdata['textarea'] = tmpl_textarea('data[text]', $data['text']); $fdata['expire'] = $expire; $this->fdata = $fdata; }