function createRecord($table, $insert_array, $trigger_field = false, $trigger_value = false, $day = false, $month = false, $year = false, $send_condition = false, $any_modification = false, $register_changes = false, $on_new_record_only = false, $store_row = false, $if_not_exists = false, $run_in_cron = false) { global $CFG; if ($CFG->backstage_mode) { $HTML = ''; if ($CFG->pm_editor) { if (!$this->edit_record) { $this->HTML[] = "[create_record]" . self::peLabel($CFG->method_id, 'createRecord'); } else { $this->HTML[] = "[edit_record]" . self::peLabel($CFG->method_id, 'editRecord'); } } /* $HTML .= ' <input type="hidden" name="trigger_field1[]" value="'.$trigger_field.'" /> <input type="hidden" name="trigger_value1[]" value="'.$trigger_value.'" /> <input type="hidden" name="create_record_table[]" value="'.$table.'" /> '; $this->HTML[] = $HTML; */ } if ($run_in_cron && !$CFG->in_cron) { return false; } elseif ($run_in_cron && $CFG->in_cron) { $modified = true; } //used to have this ($CFG->ignore_request == $table) return false. Don't remember why. if ((is_array($this->errors) || !($this->save_called || $CFG->save_called) || !$_REQUEST[$this->name] || $_REQUEST['bypass_create_record']) && !$CFG->in_cron) { return false; } if (!$on_new_record_only && $this->record_created && !$trigger_field || $on_new_record_only && !$this->record_created) { return false; } if ($send_condition) { $send_condition = String::doFormulaReplacements($send_condition, $this->info, 1); if (!eval("if ({$send_condition}) { return 1;} else { return 0;}")) { return false; } } if ($register_changes) { $changes = '<div class="show_details"><a onclick="showDetails(this);return false;" href="#">' . $CFG->comments_show_details . '</a><a onclick="hideDetails(this);return false;" style="display:none;" href="#">' . $CFG->comments_hide_details . '</a></div><div class="details" style="display:none;">'; } if ($this->info && $register_changes) { foreach ($this->info as $name => $value) { $grid_input_modified = false; if (@in_array($name, $_REQUEST['grid_inputs'])) { if (is_array($this->info[$name])) { if (is_array($this->old_info[$name])) { foreach ($this->old_info[$name] as $id => $row) { foreach ($row as $k => $v) { $key = $row['id']; if (!empty($v) && $v != 'N' && $k != 'id' && $k != 'f_id') { $compare[$key][$k] = $v; } } } if ($compare) { ksort($compare); $compare = array_values($compare); } } $i = 0; foreach ($this->info[$name] as $id => $row) { foreach ($row as $k => $v) { if (!empty($v)) { $filtered[$i] = $row; } } $i++; } if ($filtered && $compare) { $i = 0; foreach ($filtered as $array) { if (is_array($array)) { foreach ($array as $k => $v) { if ($v != $compare[$i][$k] && (!empty($v) && !empty($compare[$i][$k]))) { $grid_input_modified = true; } } } $i++; } if (!$grid_input_modified) { if (count($filtered) != count($compare)) { $grid_input_modified = true; } } } elseif ($compare && !$filtered || $filtered && !$compare) { $grid_input_modified = true; } } } if ($name == 'cat_selects') { if (is_array($this->info[$name])) { @asort($this->info[$name]); @asort($this->old_info[$name]); $this->info[$name] = @array_values($this->info[$name]); $this->old_info[$name] = @array_values($this->old_info[$name]); foreach ($this->info[$name] as $key => $arr) { @asort($arr); $this->info[$name][$key] = @array_values($arr); } if (is_array($this->old_info[$name])) { foreach ($this->old_info[$name] as $key => $arr) { @asort($arr); $this->old_info[$name][$key] = @array_values($arr); } } if ($this->info[$name] != $this->old_info[$name]) { $modified = true; $changes .= '<b>' . $name . '</b> ' . $CFG->comments_set_to . ' ' . (is_array($value) ? print_r($value, true) : $value) . '<br/>'; } } } elseif (strip_tags($this->info[$name]) != strip_tags($this->old_info[$name]) && !@in_array($name, $_REQUEST['grid_inputs']) || $grid_input_modified) { $modified = true; $changes .= '<b>' . $name . '</b> ' . $CFG->comments_set_to . ' ' . (is_array($value) ? print_r($value, true) : $value) . '<br/>'; } $bypass = false; $compare = false; $filtered = false; } } if ($register_changes) { $changes .= '</div>'; } if ($on_new_record_only && $this->record_created) { $modified = true; } if ($this->info[$trigger_field] != $this->old_info[$trigger_field] || $modified) { if ($this->info[$trigger_field] == $trigger_value || !$trigger_value && $trigger_field || $modified) { if (!is_array($insert_array) && stristr($insert_array, 'array:')) { $insert_array = str_ireplace('array:', '', $insert_array); $ia1 = explode(',', $insert_array); if (is_array($ia1)) { foreach ($ia1 as $v) { if (strstr($v, '=>')) { $ia2 = explode('=>', $v); $ia3[$ia2[0]] = $ia2[1]; $last_key = $ia2[0]; } else { $ia3[$last_key] .= ',' . $v; } } } unset($insert_array); $insert_array = $ia3; } if (is_array($insert_array)) { foreach ($insert_array as $new_field => $old_field) { if ($old_field == 'curdate') { $insert_values[$new_field] = date('Y-m-d 00:00:00'); } elseif ($old_field == 'curtime') { $insert_values[$new_field] = date('Y-m-d H:i:s', time() + Settings::mysqlTimeDiff() * 3600); } elseif ($old_field == 'user_id') { $insert_values[$new_field] = User::$info['id']; } elseif ($old_field == 'record_id') { $insert_values[$new_field] = $this->record_id; } elseif (strstr($old_field, '(') && strstr($old_field, ')')) { if ($this->record_created) { $this->old_info['id'] = $this->record_id; } $formula = String::doFormulaReplacements($old_field, $this->old_info, 1); $insert_values[$new_field] = eval("return ({$formula});"); } elseif ($old_field == 'current_url') { $insert_values[$new_field] = $CFG->url; } elseif (!is_array($old_field)) { if (array_key_exists($old_field, $this->info)) { $insert_values[$new_field] = $this->info[$old_field]; } else { $insert_values[$new_field] = $old_field; } } else { $insert_values[$new_field] = DB::getForeignValue(implode(',', $old_field), $this->info['id']); } } if ($register_changes) { $insert_values['comments'] = $changes; } if ($store_row && $table == 'comments') { if ($this->edit_record && $table != $this->table) { $row = DB::getRecord($table, $this->edit_record_field_id, 0, 1); $insert_values['f_table_row'] = serialize($row); } else { $insert_values['f_table_row'] = serialize($this->info); } } $CFG->ignore_request = $table; $CFG->bypass_unserialize = true; $this->edit_record_id_field = $this->edit_record_id_field ? $this->edit_record_id_field : $this->record_id; if (!$this->edit_record) { if ($if_not_exists) { $insert_values1 = $insert_values; if ($k = array_search($this->record_id, $insert_values1)) { unset($insert_values1[$k]); } if (DB::recordExists($table, $insert_values1)) { return false; } } $this->create_record[] = array('table' => $table, 'insert_values' => $insert_values); //echo 'Insert:'; //print_ar($insert_values); } else { $this->create_record[] = array('edit' => 1, 'table' => $table, 'insert_values' => $insert_values, 'id' => $this->edit_record_field_id); //echo 'Update:'; //print_ar($insert_values); } } } } }
public static function parseVariables($variables, $row, $record_id = 0, $url = false, $update_variable_values = false) { global $CFG; $reserved_keywords = array('current_url', 'action', 'bypass', 'is_tab'); if (is_array($variables)) { foreach ($variables as $k => $v) { $is_formula = strstr($v, '(') && strstr($v, ')'); $k1 = $url ? "{$url}[{$k}]" : $k; $v1 = $is_formula ? $v : str_replace('[', '', str_replace(']', '', $v)); if (strstr($v1, '(') && strstr($v1, ')')) { $formula = String::doFormulaReplacements($v1, $row, 1); $v1 = eval("return ({$formula});"); } if (in_array($k, $reserved_keywords)) { $variables1[$k] = $v; } elseif ($k == 'record_id') { $variables1[$k1] = $is_formula ? $v1 : $record_id; } elseif ($k == 'id') { $variables1[$k] = $is_formula ? $v1 : $record_id; if ($update_variable_values) { $variables1['record_id'] = $is_formula ? $v1 : $record_id; } } elseif ($v1 == 'id') { $variables1[$k1] = $is_formula ? $v1 : $record_id; } elseif ($v1 == 'curdate') { $variables1[$k1] = date('Y-m-d 00:00:00'); } elseif ($v1 == 'curtime') { $variables1[$k1] = date('Y-m-d H:i:s', time() + Settings::mysqlTimeDiff() * 3600); } elseif ($k == 'user_id') { $variables1[$k1] = User::$info['id']; } elseif (strstr($v1, 'count')) { $p = explode('(', $v1); $v1 = str_replace(')', '', $p[1]); $variables1[$k1] = DB::countRows($v1); } elseif (strstr($v1, '.')) { $parts = explode('.', $v1); $sql = "SELECT {$parts[1]} FROM {$parts[0]} WHERE f_id = {$record_id}"; $result = db_query_array($sql); if ($result) { $m1 = $parts[1]; $variables1[$k1] = $result[0][$m1]; } } elseif (strstr($v1, ',')) { $variables1[$k1] = DB::getForeignValue(implode(',', $v1), $row); } else { self::replaceSystemVars($v1); if (strstr($v1, '++')) { $v1 = $row[str_replace('++', '', $v1)] + 1; } elseif (strstr($v1, '--')) { $v1 = $row[str_replace('--', '', $v1)] - 1; } else { $v1 = array_key_exists($v1, $row) ? $row[$v1] : $v; } $variables1[$k1] = $v1; } } } if ($record_id > 0 && $update_variable_values) { $variables1['record_id'] = $record_id; } return $variables1; }
private function show($comments) { global $CFG; if ($comments) { echo '<ul>'; foreach ($comments as $comment) { $elapsed = time() + Settings::mysqlTimeDiff() * 3600 - strtotime($comment['date']); if ($elapsed < 60) { $time_ago = $CFG->comments_less_than_minute; } elseif ($elapsed > 60 && $elapsed < 60 * 60) { $minutes = floor($elapsed / 60); $time_ago = str_ireplace('[field]', $minutes, $CFG->comments_minutes_ago); } elseif ($elapsed > 60 * 60 && $elapsed < 60 * 60 * 24) { $hours = floor($elapsed / 60 / 60); $time_ago = str_ireplace('[field]', $hours, $CFG->comments_hours_ago); } elseif ($elapsed > 60 * 60 * 24 && $elapsed < 60 * 60 * 24 * 30.4) { $days = floor($elapsed / 60 / 60 / 24); $time_ago = str_ireplace('[field]', $days, $CFG->comments_days_ago); } else { $months = floor($elapsed / 60 / 60 / 24 / 30.4); $time_ago = str_ireplace('[field]', $months, $CFG->comments_months_ago); } if ($comment['user_id'] > 0) { $user = DB::getRecord($this->user_table, $comment['user_id'], false, true); $name = !empty($comment['website']) ? Link::url($comment['website'], $user['user']) : $user['user']; } else { $name = !empty($comment['website']) ? Link::url($comment['website'], $comment['name']) : $comment['name']; } $short = $this->short_version ? '_short' : ''; $icon = $comment['type'] ? eval('return $CFG->comment_type_' . $comment['type'] . ';') : $CFG->comment_type_1; $action = $comment['type'] ? eval('return $CFG->comments_action_' . $comment['type'] . $short . ';') : $CFG->comments_wrote_label; $action = String::doFormulaReplacements($action, unserialize($comment['f_table_row']), 1, 1); echo ' <li id="comment_' . $comment['id'] . '" class="level_' . $comment['type'] . '"> <div class="c_head">'; if ($this->fields) { foreach ($this->fields as $f_name => $field) { $CFG->o_method_id = $field['method_id']; $CFG->o_method_name = 'field'; $record = new Record($field['table'], $comment['record_id']); echo '<div class="added_field">' . $record->field($field['name'], $field['caption'], $field['subtable'], $field['subtable_fields'], $field['link_url'], $field['concat_char'], true, $field['f_id_field'], $field['order_by'], $field['order_asc'], $comment['record_id'], $field['link_is_tab'], $field['limit_is_curdate'], false, $field['link_id_field']) . '</div>'; } } echo ' ' . $icon . ' ' . $name . ' (' . $time_ago . ') ' . $action . ' </div>'; if (!$this->short_version) { echo ' <div class="c_comment"> ' . (strlen($comment['comments']) != strlen(strip_tags($comment['comments'])) ? $comment['comments'] : nl2br($comment['comments'])) . ' </div>'; } echo ' ' . ($comment['type'] <= 1 && !$this->short_version ? '<div class="c_reply"><a href="#" onclick="showReplyBox(' . $comment['id'] . ',' . $this->i . ');return false;">' . $CFG->comments_reply_label . '</a></div>' : '') . ' <div class="c_form"></div> </li>'; if (is_array($comment['children'])) { Comments::show($comment['children']); } } echo '<div style="clear:both;height:0;"></div></ul>'; } }
function getTimeRemaining() { $diff = Settings::mysqlTimeDiff(); return strtotime($this->item_info['exp_date']) - time() + 3600 + $diff * 3600; }