hidden('end', $end); $total = $btotal = $ltotal = 0; for ($i = 0, $date_ = $begin; date1_greater_date2($end, $date_); $i++) { start_row(); $_POST['amount' . $i] = number_format2(get_only_budget_trans_from_to($date_, $date_, $_POST['account'], $_POST['dim1'], $_POST['dim2']), 0); label_cell($date_); if (!isset($_POST['amount' . $i])) { $_POST['amount' . $i] = '0'; } amount_cells(null, 'amount' . $i, null, 15, null, 0); if ($showdims) { $d = get_budget_trans_from_to($date_, $date_, $_POST['account'], $_POST['dim1'], $_POST['dim2']); label_cell(number_format2($d, 0), "nowrap align=right"); $btotal += $d; } $lamount = get_gl_trans_from_to(add_years($date_, -1), add_years(end_month($date_), -1), $_POST['account'], $_POST['dim1'], $_POST['dim2']); $total += input_num('amount' . $i); $ltotal += $lamount; label_cell(number_format2($lamount, 0), "nowrap align=right"); $date_ = add_months($date_, 1); end_row(); } start_row(); label_cell("<b>" . tr("Total") . "</b>"); label_cell("<b>" . number_format2($total, 0) . "</b>", 'align=right'); if ($showdims) { label_cell("<b>" . number_format2($btotal, 0) . "</b>", "nowrap align=right"); } label_cell("<b>" . number_format2($ltotal, 0) . "</b>", "nowrap align=right"); end_row(); end_table(1);
function process_form() { global $vars, $phpcdb, $phpc_cal, $phpcid, $phpc_script, $phpc_user; // When modifying events, this is the value of the checkbox that // determines if the date should change $modify_occur = !isset($vars['eid']) || !empty($vars['phpc-modify']); if ($modify_occur) { $start_ts = get_timestamp("start"); $end_ts = get_timestamp("end"); switch ($vars["time-type"]) { case 'normal': $time_type = 0; break; case 'full': $time_type = 1; break; case 'tba': $time_type = 2; break; default: soft_error(__("Unrecognized Time Type.")); } $duration = $end_ts - $start_ts; if ($duration < 0) { message(__("An event cannot have an end earlier than its start.")); return display_form(); } } verify_token(); if (0) { permission_error(__('You do not have permission to write to this calendar.')); } if ($phpc_cal->can_create_readonly() && !empty($vars['readonly'])) { $readonly = true; } else { $readonly = false; } $catid = empty($vars['catid']) ? false : $vars['catid']; if (!isset($vars['eid'])) { $modify = false; $eid = $phpcdb->create_event($phpcid, $phpc_user->get_uid(), $vars["subject"], $vars["description"], $readonly, $catid); } else { $modify = true; $eid = $vars['eid']; $phpcdb->modify_event($eid, $vars['subject'], $vars['description'], $readonly, $catid); if ($modify_occur) { $phpcdb->delete_occurrences($eid); } } if ($modify_occur) { $oid = $phpcdb->create_occurrence($eid, $time_type, $start_ts, $end_ts); $occurrences = 1; switch ($vars["repeats"]) { case "never": break; case 'daily': if (!isset($vars["every-day"])) { soft_error(__("Required field \"every-day\" is not set.")); } $ndays = $vars["every-day"]; if ($ndays < 1) { soft_error(__("every-day must be greater than 1")); } $daily_until = get_timestamp("daily-until"); while ($occurrences <= 730) { $start_ts = add_days($start_ts, $ndays); $end_ts = add_days($end_ts, $ndays); if (days_between($start_ts, $daily_until) < 0) { break; } $phpcdb->create_occurrence($eid, $time_type, $start_ts, $end_ts); $occurrences++; } break; case 'weekly': if (!isset($vars["every-week"])) { soft_error(__("Required field \"every-week\" is not set.")); } if ($vars["every-week"] < 1) { soft_error(__("every-week must be greater than 1")); } $ndays = $vars["every-week"] * 7; $weekly_until = get_timestamp("weekly-until"); while ($occurrences <= 730) { $start_ts = add_days($start_ts, $ndays); $end_ts = add_days($end_ts, $ndays); if (days_between($start_ts, $weekly_until) < 0) { break; } $phpcdb->create_occurrence($eid, $time_type, $start_ts, $end_ts); $occurrences++; } break; case 'monthly': if (!isset($vars["every-month"])) { soft_error(__("Required field \"every-month\" is not set.")); } if ($vars["every-month"] < 1) { soft_error(__("every-month must be greater than 1")); } $nmonths = $vars["every-month"]; $monthly_until = get_timestamp("monthly-until"); while ($occurrences <= 730) { $start_ts = add_months($start_ts, $nmonths); $end_ts = add_months($end_ts, $nmonths); if (days_between($start_ts, $monthly_until) < 0) { break; } $phpcdb->create_occurrence($eid, $time_type, $start_ts, $end_ts); $occurrences++; } break; case 'yearly': if (!isset($vars["every-year"])) { soft_error(__("Required field \"every-year\" is not set.")); } if ($vars["every-year"] < 1) { soft_error(__("every-month must be greater than 1")); } $nyears = $vars["every-year"]; $yearly_until = get_timestamp("yearly-until"); while ($occurrences <= 730) { $start_ts = add_years($start_ts, $nyears); $end_ts = add_years($end_ts, $nyears); if (days_between($start_ts, $yearly_until) < 0) { break; } $phpcdb->create_occurrence($eid, $time_type, $start_ts, $end_ts); $occurrences++; } break; default: soft_error(__("Invalid event type.")); } } if ($eid != 0) { if ($modify) { $message = __("Modified event: "); } else { $message = __("Created event: "); } /* before return message_redirect(tag($eid, $message, create_event_link('', 'display_event', $eid)), */ return message_redirect(tag('', $message, create_event_link('', 'display_event', '')), "{$phpc_script}?action=display_event&phpcid={$phpcid}&oid={$oid}"); /* <-- before last paremeter was &eid=$eid instead of &oid=$oid */ } else { return message_redirect(__('Error submitting event.'), "{$phpc_script}?action=display_month&phpcid={$phpcid}"); } }
<?php //function returns function add_years($age, $add_years) { $age += $add_years; return $age; //Can only do one return in a fuction } $sebastian = add_years(45, 5); $joe = add_years(25, 5); $ted = add_years(65, 5); ?> <html> <body> <h1><?php echo $sebastian; ?> </h1> <h1><?php echo $joe; ?> </h1> <h1><?php echo $ted; ?> </h1> </body> </html>
function days_between($ts1, $ts2) { // First date always comes first if ($ts1 > $ts2) { return -days_between($ts2, $ts1); } // If we're in different years, keep adding years until we're in // the same year if (date('Y', $ts2) > date('Y', $ts1)) { return days_in_year_ts($ts1) + days_between(add_years($ts1, 1), $ts2); } // The years are equal, subtract day of the year of each return date('z', $ts2) - date('z', $ts1); }
function date_cells($label, $name, $title = null, $check = null, $inc_days = 0, $inc_months = 0, $inc_years = 0, $params = null, $submit_on_change = false) { global $use_date_picker, $path_to_root, $Ajax; if (!isset($_POST[$name]) || $_POST[$name] == "") { if ($inc_years == 1001) { $_POST[$name] = null; } else { $dd = Today(); if ($inc_days != 0) { $dd = add_days($dd, $inc_days); } if ($inc_months != 0) { $dd = add_months($dd, $inc_months); } if ($inc_years != 0) { $dd = add_years($dd, $inc_years); } $_POST[$name] = $dd; } } if ($use_date_picker) { $calc_image = file_exists("{$path_to_root}/themes/" . user_theme() . "/images/cal.gif") ? "{$path_to_root}/themes/" . user_theme() . "/images/cal.gif" : "{$path_to_root}/themes/default/images/cal.gif"; $post_label = "<a tabindex='-1' href=\"javascript:date_picker(document.getElementsByName('{$name}')[0]);\">" . "\t<img src='{$calc_image}' width='15' height='15' border='0' alt='" . _('Click Here to Pick up the date') . "'></a>\n"; } else { $post_label = ""; } $class = $submit_on_change ? 'date active form-control' : 'date form-control'; $aspect = $check ? 'aspect="cdate"' : ''; if ($check && get_post($name) != Today()) { $aspect .= ' style="color:#FF0000"'; } default_focus($name); $size = user_date_format() > 3 ? 11 : 10; $controlAsString = "<div class=\"input-group\">" . "<input type=\"text\" name=\"{$name}\" class=\"{$class}\" {$aspect} size=\"{$size}\" maxlength=\"12\" value=\"" . $_POST[$name] . "\"" . ($title ? " title='{$title}'" : '') . " > " . "<span class=\"input-group-addon\">{$post_label}</span>" . "</div>"; View::get()->addControl(View::controlFromRenderedString(View::CONTROL_DATE, $label, $controlAsString)); // CONTROL_DATE? CP 2014-11 $Ajax->addUpdate($name, $name, $_POST[$name]); }
function process_form() { global $vars, $phpcdb, $phpc_script, $phpc_user, $phpc_cal; // When modifying events, this is the value of the checkbox that // determines if the date should change $modify_occur = !isset($vars['eid']) || !empty($vars['phpc-modify']); if ($modify_occur) { $start_ts = get_timestamp("start"); $end_ts = get_timestamp("end"); switch ($vars["time-type"]) { case 'normal': $time_type = 0; break; case 'full': $time_type = 1; break; case 'tba': $time_type = 2; break; default: soft_error(__("Unrecognized Time Type.")); } $duration = $end_ts - $start_ts; if ($duration < 0) { throw new Exception(__("An event cannot have an end earlier than its start.")); } } verify_token(); if (!isset($vars['cid'])) { throw new Exception(__("Calendar ID is not set.")); } $cid = $vars['cid']; $calendar = $phpcdb->get_calendar($cid); if (!$calendar->can_write()) { permission_error(__('You do not have permission to write to this calendar.')); } if ($calendar->can_create_readonly() && !empty($vars['readonly'])) { $readonly = true; } else { $readonly = false; } $catid = empty($vars['catid']) ? false : $vars['catid']; if (!isset($vars['eid'])) { $modify = false; $eid = $phpcdb->create_event($cid, $phpc_user->get_uid(), $vars["subject"], $vars["description"], $readonly, $catid); } else { $modify = true; $eid = $vars['eid']; $phpcdb->modify_event($eid, $vars['subject'], $vars['description'], $readonly, $catid); if ($modify_occur) { $phpcdb->delete_occurrences($eid); } } foreach ($phpc_cal->get_fields() as $field) { $fid = $field['fid']; if (empty($vars["phpc-field-{$fid}"])) { if ($field['required']) { throw new Exception(sprintf(__('Field "%s" is required but was not set.'), $field['name'])); } continue; } $phpcdb->add_event_field($eid, $fid, $vars["phpc-field-{$fid}"]); } if ($modify_occur) { $occurrences = 0; $n = 1; $until = $start_ts; switch ($vars['repeats']) { case 'daily': check_input("every-day"); $n = $vars["every-day"]; $until = get_timestamp("daily-until"); break; case 'weekly': check_input("every-week"); $n = $vars["every-week"] * 7; $until = get_timestamp("weekly-until"); break; case 'monthly': check_input("every-month"); $n = $vars["every-month"]; $until = get_timestamp("monthly-until"); break; case 'yearly': check_input("every-year"); $n = $vars["every-year"]; $until = get_timestamp("yearly-until"); break; } if ($n < 1) { soft_error(__('Increment must be 1 or greater.')); } while ($occurrences <= 730 && days_between($start_ts, $until) >= 0) { $oid = $phpcdb->create_occurrence($eid, $time_type, $start_ts, $end_ts); $occurrences++; switch ($vars["repeats"]) { case 'daily': case 'weekly': $start_ts = add_days($start_ts, $n); $end_ts = add_days($end_ts, $n); break; case 'monthly': $start_ts = add_months($start_ts, $n); $end_ts = add_months($end_ts, $n); break; case 'yearly': $start_ts = add_years($start_ts, $n); $end_ts = add_years($end_ts, $n); break; default: break 2; } } } if ($eid != 0) { if ($modify) { $message = __("Modified event: "); } else { $message = __("Created event: "); } return message_redirect(tag('', $message, create_event_link($eid, 'display_event', $eid)), "{$phpc_script}?action=display_event&eid={$eid}"); } else { return message_redirect(__('Error submitting event.'), "{$phpc_script}?action=display_month&phpcid={$cid}"); } }