public function backup() { init_db($this); $this->deleteConfFile(); $filecontents = array(); foreach ($this->elements as $key1 => $value1) { if (is_array($this->elements[$key1])) { foreach ($value1 as $key2 => $value2) { if (is_array($value2)) { foreach ($value2 as $key3 => $value3) { if (is_array($value3)) { foreach ($value3 as $key4 => $value4) { $buf = $this->elements[$key1][$key2][$key3][$key4]; if (!isset($filecontents[$key1][$key2][$key3])) { $filecontents[$key1][$key2][$key3] = array(); } $filecontents[$key1][$key2][$key3][$key4] = $buf->content; } } else { $buf = $this->elements[$key1][$key2][$key3]; if (!isset($filecontents[$key1][$key2])) { $filecontents[$key1][$key2] = array(); } $filecontents[$key1][$key2][$key3] = $buf->content; } } } else { $buf = $this->elements[$key1][$key2]; if (!isset($filecontents[$key1])) { $filecontents[$key1] = array(); } $filecontents[$key1][$key2] = $buf->content; } } } else { $buf = $this->elements[$key1]; $filecontents[$key1] = $buf->content; } } return file_put_contents($this->conf_file, json_serialize($filecontents), LOCK_EX); }
public function update($conf) { if (array_key_exists($conf->getAttribute('id'), $this->cache)) { unset($this->cache[$conf->getAttribute('id')]); } if ($this->isOK($conf)) { $query = 'UPDATE#1 SET '; $attributes = $conf->getAttributesList(); foreach ($attributes as $key) { $value = $conf->getAttribute($key); if ($key == 'values') { $value = json_serialize($value); } $query .= '`' . $key . '` = \'' . mysql_escape_string($value) . '\' , '; } $query = substr($query, 0, -2); // del the last , $query .= ' WHERE `id` =\'' . $conf->getAttribute('id') . '\''; $sql2 = SQL::getInstance(); $res = $sql2->DoQuery($query, self::table); if ($res === false) { return false; } return true; } return false; }
function json_serialize($data) { if (is_assoc_array($data)) { $json = array(); foreach ($data as $key => $value) { array_push($json, '"' . $key . '": ' . json_serialize($value)); } return '{' . implode(', ', $json) . '}'; } if (is_array($data)) { $json = array(); foreach ($data as $value) { array_push($json, json_serialize($value)); } return '[' . implode(', ', $json) . ']'; } if (is_int($data) || is_float($data)) { return $data; } if (is_bool($data)) { return $data ? 'true' : 'false'; } return '"' . encode_for_json($data) . '"'; }
private static function export_infos($infos_) { return json_serialize($infos_); }
$data[0]['res_id'] = '155'; $data[0]['url'] = 'http://www.11google.com'; $data[0]['title'] = 'tes data'; $data[0]['category_id'] = '1'; $data[0]['description'] = 'tes desc'; $data[1]['res_id'] = '157'; $data[1]['url'] = 'http://www.11google2.com'; $data[1]['title'] = 'tes data2'; $data[1]['category_id'] = '1'; $data[1]['description'] = "tes desc2's \nsdo"; $data[2]['res_id'] = '198'; $data[2]['url'] = 'http://www.11google3.com'; $data[2]['title'] = 'tes data3'; $data[2]['category_id'] = '12'; $data[2]['description'] = "tes desc3\"dsfj'dfdfd"; $out = json_serialize($data); // send data with curl $api_url = 'http://localhost/indexu_api/api/api.php'; $post['api_key'] = 'sjdfsidyr984idfjsdfhsdfh'; $post['act'] = 'res_edit'; $post['data'] = $out; $result = ddcurl_post($api_url,$post); print $result; ?> <p>Done.</p>
/** * Add UI element to copy event invitations or updates to the calendar */ public function mail_messagebody_html($p) { // load iCalendar functions (if necessary) if (!empty($this->ics_parts)) { $this->get_ical(); } $html = ''; foreach ($this->ics_parts as $mime_id) { $part = $this->message->mime_parts[$mime_id]; $charset = $part->ctype_parameters['charset'] ? $part->ctype_parameters['charset'] : RCMAIL_CHARSET; $events = $this->ical->import($this->message->get_part_content($mime_id), $charset); $title = $this->gettext('title'); $date = rcube_utils::anytodatetime($this->message->headers->date); // successfully parsed events? if (empty($events)) { continue; } // show a box for every event in the file foreach ($events as $idx => $event) { // Begin mod by Rosali (Google sends the ics inline and attached -> avoid duplicates with same UID - https://issues.kolab.org/show_bug.cgi?id=3585) $uid = $event['uid'] ? $event['uid'] : md5(serialize($event)); if (isset($this->ics_parts_filtered[$uid])) { continue; } $this->ics_parts_filtered[$uid] = 1; // End mod by Rosali if ($event['_type'] != 'event' && $event['_type'] != 'task') { // skip non-event objects (#2928) // Mod by Rosali (don't skip tasks) continue; } // define buttons according to method if ($this->ical->method == 'REPLY') { $driver = $this->get_default_driver(); $existing = $driver->get_event($event['uid']); $calendar_saveto = new html_hiddenfield(array('class' => 'calendar-saveto', 'value' => $existing['calendar'])); // Mod by Rosali (always pass calendar to GUI) if ($calendar_saveto) { $title = $this->gettext('itipreply'); $buttons = html::tag('input', array('type' => 'button', 'class' => 'button', 'onclick' => "rcube_calendar.add_event_from_mail('" . JQ($mime_id . ':' . $idx) . "', this)", 'value' => $this->gettext('updateattendeestatus'))) . $calendar_saveto->show(); } } else { if ($this->ical->method == 'REQUEST') { $emails = $this->get_user_emails(); $title = $event['sequence'] > 0 ? $this->gettext('itipupdate') : $this->gettext('itipinvitation'); // add (hidden) buttons and activate them from asyncronous request foreach (array('accepted', 'tentative', 'declined') as $method) { $rsvp_buttons .= html::tag('input', array('type' => 'button', 'class' => "button {$method}", 'onclick' => "rcube_calendar.add_event_from_mail('" . JQ($mime_id . ':' . $idx) . "', this, '{$method}')", 'value' => $this->gettext('itip' . $method))); } $import_button = html::tag('input', array('type' => 'button', 'class' => 'button', 'onclick' => "rcube_calendar.add_event_from_mail('" . JQ($mime_id . ':' . $idx) . "', this)", 'value' => $this->gettext('importtocalendar'))); // check my status $status = 'unknown'; foreach ($event['attendees'] as $attendee) { if ($attendee['email'] && in_array(strtolower($attendee['email']), $emails)) { $status = !empty($attendee['status']) ? strtoupper($attendee['status']) : 'NEEDS-ACTION'; break; } } $dom_id = asciiwords($event['uid'], true); $buttons = html::div(array('id' => 'rsvp-' . $dom_id, 'style' => 'display:none'), $rsvp_buttons); $buttons .= html::div(array('id' => 'import-' . $dom_id, 'style' => 'display:none'), $import_button); $buttons_pre = html::div(array('id' => 'loading-' . $dom_id, 'class' => 'rsvp-status loading'), $this->gettext('loading')); $changed = is_object($event['changed']) ? $event['changed'] : $date; $script = json_serialize(array('uid' => $event['uid'], 'changed' => $changed ? $changed->format('U') : 0, 'sequence' => intval($event['sequence']), 'fallback' => $status)); $this->rc->output->add_script("rcube_calendar.fetch_event_rsvp_status({$script})", 'docready'); } else { if ($this->ical->method == 'CANCEL') { $title = $this->gettext('itipcancellation'); // create buttons to be activated from async request checking existence of this event in local calendars $button_import = html::tag('input', array('type' => 'button', 'class' => 'button', 'onclick' => "rcube_calendar.add_event_from_mail('" . JQ($mime_id . ':' . $idx) . "', this)", 'value' => $this->gettext('importtocalendar'))); $button_remove = html::tag('input', array('type' => 'button', 'class' => 'button', 'onclick' => "rcube_calendar.remove_event_from_mail('" . JQ($event['uid']) . "', '" . JQ($event['title']) . "')", 'value' => $this->gettext('removefromcalendar'))); $dom_id = asciiwords($event['uid'], true); $buttons = html::div(array('id' => 'rsvp-' . $dom_id, 'style' => 'display:none'), $button_remove); $buttons .= html::div(array('id' => 'import-' . $dom_id, 'style' => 'display:none'), $button_import); $buttons_pre = html::div(array('id' => 'loading-' . $dom_id, 'class' => 'rsvp-status loading'), $this->gettext('loading')); $changed = is_object($event['changed']) ? $event['changed'] : $date; $script = json_serialize(array('uid' => $event['uid'], 'changed' => $changed ? $changed->format('U') : 0, 'sequence' => intval($event['sequence']), 'fallback' => 'CANCELLED')); $this->rc->output->add_script("rcube_calendar.fetch_event_rsvp_status({$script})", 'docready'); } else { // get a list of writeable calendars // Begin mod by Rosali (https://gitlab.awesome-it.de/kolab/roundcube-plugins/issues/33) $driver = $this->get_default_driver(); $calendars = $driver->list_calendars(false, true); $calendar_select = new html_select(array('name' => 'calendar', 'class' => 'calendar-saveto', 'is_escaped' => true)); // Mod by Rosali (calendar selector can exist multiple times - can't be referenced by ID) $numcals = 0; foreach ($calendars as $calendar) { $driver = $this->get_driver_by_cal($calendar['calendar_id']); if ($driver->readonly !== true) { $calendar_select->add($calendar['name'], $calendar['id']); $numcals++; } } } } } if ($numcals > 0) { $buttons = html::tag('input', array('type' => 'button', 'class' => 'button', 'onclick' => "rcube_calendar.add_event_from_mail('" . JQ($mime_id . ':' . $idx) . "', this)", 'value' => $this->gettext('importtocalendar'))) . $calendar_select->show($this->rc->config->get('calendar_default_calendar')); } // show event details with buttons if ($buttons) { $html .= html::div('calendar-invitebox', $this->ui->event_details_table($event, $title) . $buttons_pre . html::div('rsvp-buttons', $buttons)); } // Emd mod by Rosli // limit listing if ($idx >= 3) { break; } } } // prepend event boxes to message body if ($html) { $this->ui->init(); $p['content'] = $html . $p['content']; $this->rc->output->add_label('calendar.savingdata', 'calendar.deleteventconfirm', 'calendar.declinedeleteconfirm'); } return $p; }
/** * GUI object 'preloader' * Loads javascript code for images preloading * * @param array Named parameters * @return void */ private function preloader($attrib) { $images = preg_split('/[\\s\\t\\n,]+/', $attrib['images'], -1, PREG_SPLIT_NO_EMPTY); $images = array_map(array($this, 'abs_url'), $images); if (empty($images) || $this->app->task == 'logout') { return; } $this->add_script('var images = ' . json_serialize($images) . '; for (var i=0; i<images.length; i++) { img = new Image(); img.src = images[i]; }', 'docready'); }
public static function save($task_) { Logger::debug('main', 'Starting Abstract_Task::save for \'' . $task_->id . '\''); $SQL = SQL::getInstance(); $id = $task_->id; if (!Abstract_Task::exists($id)) { Logger::debug('main', "Abstract_Task::save({$task_}) task does NOT exist, we must create it"); if (!Abstract_Task::create($task_)) { Logger::error('main', "Abstract_Task::save({$task_}) Abstract_Task::create failed"); return false; } } if (is_array(@$task_->applications)) { $apps = $task_->applications; } else { $apps = array(); } $SQL->DoQuery('UPDATE #1 SET @2=%3,@4=%5,@6=%7,@8=%9,@10=%11,@12=%13,@14=%15,@16=%17 WHERE @18 = %19 LIMIT 1', self::table, 'type', $task_->type, 'job_id', $task_->job_id, 'server', $task_->server, 'status', $task_->status, 't_begin', $task_->t_begin, 't_end', $task_->t_end, 'applications_line', @$task_->applications_line, 'applications', json_serialize(array_map("Application::toArray", $apps)), 'id', $id); return true; }
public static function save($user_prefs_) { $sql = SQL::getInstance(); return $res = $sql->DoQuery('INSERT INTO #1 (@2,@3,@4,@5,@6) VALUES (%7,%8,%9,%10,%11)', self::$table, 'login', 'key', 'container', 'element_id', 'value', $user_prefs_->login, $user_prefs_->key, $user_prefs_->container, $user_prefs_->element_id, json_serialize($user_prefs_->value)); }
/** * add configuration to client output (js) * @param array $args * @return array */ function render_page($args) { // add the keys to client output (js) if (in_array($this->rcmail->task, $this->rcmail->config->get('keyboard_shortcut_tasks', array('mail', 'compose', 'addressbook', 'settings', 'dummy')))) { // trigger config_get hook for other plugins which may need it $this->rcmail->config->get('keyboard_shortcuts_threads'); // populate configuarion $this->config['shortcuts'] = $this->get_shortcuts(); $this->config['commands'] = $this->get_commands(); // we need json output $config = json_serialize($this->config); $this->rcmail->output->add_script("Shortcuts.config({$config});", 'foot'); } return $args; }
/** * Return executable javascript code for all registered commands * * @return string $out */ private function get_js_commands() { $out = ''; if (!$this->framed && !empty($this->js_env)) { $out .= JS_OBJECT_NAME . '.set_env(' . json_serialize($this->js_env) . ");\n"; } foreach ($this->js_commands as $i => $args) { $method = array_shift($args); foreach ($args as $i => $arg) { $args[$i] = json_serialize($arg); } $parent = $this->framed || preg_match('/^parent\\./', $method); $out .= sprintf("%s.%s(%s);\n", ($parent ? 'if(window.parent && parent.' . JS_OBJECT_NAME . ') parent.' : '') . JS_OBJECT_NAME, preg_replace('/^parent\\./', '', $method), implode(',', $args)); } return $out; }
/** * Build inline UI elements for iTip messages */ public function mail_itip_inline_ui($event, $method, $mime_id, $task, $message_date = null, $preview_url = null) { $buttons = array(); $dom_id = asciiwords($event['uid'], true); $rsvp_status = 'unknown'; // pass some metadata about the event and trigger the asynchronous status check $changed = is_object($event['changed']) ? $event['changed'] : $message_date; $metadata = array('uid' => $event['uid'], 'changed' => $changed ? $changed->format('U') : 0, 'sequence' => intval($event['sequence']), 'method' => $method, 'task' => $task); // create buttons to be activated from async request checking existence of this event in local calendars $buttons[] = html::div(array('id' => 'loading-' . $dom_id, 'class' => 'rsvp-status loading'), $this->gettext('loading')); // on iTip REPLY we have two options: if ($method == 'REPLY') { $title = $this->gettext('itipreply'); foreach ($event['attendees'] as $attendee) { if (!empty($attendee['email']) && $attendee['role'] != 'ORGANIZER' && (empty($event['_sender']) || ($attendee['email'] == $event['_sender'] || $attendee['email'] == $event['_sender_utf']))) { $metadata['attendee'] = $attendee['email']; $rsvp_status = strtoupper($attendee['status']); if ($attendee['delegated-to']) { $metadata['delegated-to'] = $attendee['delegated-to']; } break; } } // 1. update the attendee status on our copy $update_button = html::tag('input', array('type' => 'button', 'class' => 'button', 'onclick' => "rcube_libcalendaring.add_from_itip_mail('" . JQ($mime_id) . "', '{$task}')", 'value' => $this->gettext('updateattendeestatus'))); // 2. accept or decline a new or delegate attendee $accept_buttons = html::tag('input', array('type' => 'button', 'class' => "button accept", 'onclick' => "rcube_libcalendaring.add_from_itip_mail('" . JQ($mime_id) . "', '{$task}')", 'value' => $this->gettext('acceptattendee'))); $accept_buttons .= html::tag('input', array('type' => 'button', 'class' => "button decline", 'onclick' => "rcube_libcalendaring.decline_attendee_reply('" . JQ($mime_id) . "', '{$task}')", 'value' => $this->gettext('declineattendee'))); $buttons[] = html::div(array('id' => 'update-' . $dom_id, 'style' => 'display:none'), $update_button); $buttons[] = html::div(array('id' => 'accept-' . $dom_id, 'style' => 'display:none'), $accept_buttons); } else { if ($method == 'REQUEST') { $emails = $this->lib->get_user_emails(); $title = $event['sequence'] > 0 ? $this->gettext('itipupdate') : $this->gettext('itipinvitation'); $metadata['rsvp'] = true; $metadata['sensitivity'] = $event['sensitivity']; if (is_object($event['start'])) { $metadata['date'] = $event['start']->format('U'); } // check for X-KOLAB-INVITATIONTYPE property and only show accept/decline buttons if (self::get_custom_property($event, 'X-KOLAB-INVITATIONTYPE') == 'CONFIRMATION') { $this->rsvp_actions = array('accepted', 'declined'); $metadata['nosave'] = true; } // 1. display RSVP buttons (if the user was invited) foreach ($this->rsvp_actions as $method) { $rsvp_buttons .= html::tag('input', array('type' => 'button', 'class' => "button {$method}", 'onclick' => "rcube_libcalendaring.add_from_itip_mail('" . JQ($mime_id) . "', '{$task}', '{$method}', '{$dom_id}')", 'value' => $this->gettext('itip' . $method))); } // add button to open calendar/preview if (!empty($preview_url)) { $msgref = $this->lib->ical_message->folder . '/' . $this->lib->ical_message->uid . '#' . $mime_id; $rsvp_buttons .= html::tag('input', array('type' => 'button', 'class' => "button preview", 'onclick' => "rcube_libcalendaring.open_itip_preview('" . JQ($preview_url) . "', '" . JQ($msgref) . "')", 'value' => $this->gettext('openpreview'))); } // 2. update the local copy with minor changes $update_button = html::tag('input', array('type' => 'button', 'class' => 'button', 'onclick' => "rcube_libcalendaring.add_from_itip_mail('" . JQ($mime_id) . "', '{$task}')", 'value' => $this->gettext('updatemycopy'))); // 3. Simply import the event without replying $import_button = html::tag('input', array('type' => 'button', 'class' => 'button', 'onclick' => "rcube_libcalendaring.add_from_itip_mail('" . JQ($mime_id) . "', '{$task}')", 'value' => $this->gettext('importtocalendar'))); // check my status foreach ($event['attendees'] as $attendee) { if ($attendee['email'] && in_array(strtolower($attendee['email']), $emails)) { $metadata['attendee'] = $attendee['email']; $metadata['rsvp'] = $attendee['rsvp'] || $attendee['role'] != 'NON-PARTICIPANT'; $rsvp_status = !empty($attendee['status']) ? strtoupper($attendee['status']) : 'NEEDS-ACTION'; break; } } // add itip reply message controls $rsvp_buttons .= html::div('itip-reply-controls', $this->itip_rsvp_options_ui($dom_id, $metadata['nosave'])); $buttons[] = html::div(array('id' => 'rsvp-' . $dom_id, 'class' => 'rsvp-buttons', 'style' => 'display:none'), $rsvp_buttons); $buttons[] = html::div(array('id' => 'update-' . $dom_id, 'style' => 'display:none'), $update_button); // prepare autocompletion for delegation dialog if (in_array('delegated', $this->rsvp_actions)) { $this->rc->autocomplete_init(); } } else { if ($method == 'CANCEL') { $title = $this->gettext('itipcancellation'); // 1. remove the event from our calendar $button_remove = html::tag('input', array('type' => 'button', 'class' => 'button', 'onclick' => "rcube_libcalendaring.remove_from_itip('" . JQ($event['uid']) . "', '{$task}', '" . JQ($event['title']) . "')", 'value' => $this->gettext('removefromcalendar'))); // 2. update our copy with status=cancelled $button_update = html::tag('input', array('type' => 'button', 'class' => 'button', 'onclick' => "rcube_libcalendaring.add_from_itip_mail('" . JQ($mime_id) . "', '{$task}')", 'value' => $this->gettext('updatemycopy'))); $buttons[] = html::div(array('id' => 'rsvp-' . $dom_id, 'style' => 'display:none'), $button_remove . $button_update); $rsvp_status = 'CANCELLED'; $metadata['rsvp'] = true; } } } // append generic import button if ($import_button) { $buttons[] = html::div(array('id' => 'import-' . $dom_id, 'style' => 'display:none'), $import_button); } // pass some metadata about the event and trigger the asynchronous status check $metadata['fallback'] = $rsvp_status; $metadata['rsvp'] = intval($metadata['rsvp']); $this->rc->output->add_script("rcube_libcalendaring.fetch_itip_object_status(" . json_serialize($metadata) . ")", 'docready'); // get localized texts from the right domain foreach (array('savingdata', 'deleteobjectconfirm', 'declinedeleteconfirm', 'declineattendee', 'cancel', 'itipdelegated', 'declineattendeeconfirm', 'itipcomment', 'delegateinvitation', 'delegateto', 'delegatersvpme', 'delegateinvalidaddress') as $label) { $this->rc->output->command('add_label', "itip.{$label}", $this->gettext($label)); } // show event details with buttons return $this->itip_object_details_table($event, $title) . html::div(array('class' => 'itip-buttons', 'id' => 'itip-buttons-' . asciiwords($metadata['uid'], true)), join('', $buttons)); }
/** * Return executable javascript code for all registered commands * * @return string $out */ private function get_js_commands() { $out = ''; foreach ($this->commands as $i => $args) { $method = array_shift($args); foreach ($args as $i => $arg) { $args[$i] = json_serialize($arg); } $out .= sprintf("this.%s(%s);\n", preg_replace('/^parent\\./', '', $method), implode(',', $args)); } return $out; }
public static function save($session_) { Logger::debug('main', 'Starting Abstract_Session::save for \'' . $session_->id . '\''); $SQL = SQL::getInstance(); $id = $session_->id; if (!Abstract_Session::exists($id)) { Logger::debug('main', "Abstract_Session::save({$session_}) session does NOT exist, we must create it"); if (!Abstract_Session::create($session_)) { Logger::error('main', "Abstract_Session::save({$session_}) failed to create session"); return false; } } $data = array(); $data['applications'] = array_map("Application::toArray", $session_->getPublishedApplications()); $data['running_applications'] = array_map("Application::toArray", $session_->getRunningApplications()); $data['closed_applications'] = array_map("Application::toArray", $session_->getClosedApplications()); $SQL->DoQuery('UPDATE #1 SET @2=%3,@4=%5,@6=%7,@8=%9,@10=%11,@12=%13,@14=%15,@16=%17,@18=%19,@20=%21,@22=%23,@24=%25,@26=%27 WHERE @28 = %29 LIMIT 1', self::table, 'server', $session_->server, 'client_id', $session_->client_id, 'need_creation', $session_->need_creation, 'mode', $session_->mode, 'type', $session_->type, 'status', $session_->status, 'settings', json_serialize($session_->settings), 'user_login', $session_->user_login, 'user_displayname', $session_->user_displayname, 'servers', json_serialize($session_->servers), 'applications', json_serialize($data), 'start_time', $session_->start_time, 'timestamp', time(), 'id', $id); return true; }
/** * Return executable javascript code for all registered commands * * @return string $out */ private function get_js_commands() { $out = ''; if (sizeof($this->env)) { $out .= 'this.set_env(' . json_serialize($this->env) . ");\n"; } foreach ($this->texts as $name => $text) { $out .= sprintf("this.add_label('%s', '%s');\n", $name, JQ($text)); } foreach ($this->commands as $i => $args) { $method = array_shift($args); foreach ($args as $i => $arg) { $args[$i] = json_serialize($arg); } $out .= sprintf("this.%s(%s);\n", preg_replace('/^parent\\./', '', $method), implode(',', $args)); } return $out; }
private static function saveProperty($server_, $object_property_, $db_property_, $old_property_) { $property_ = isset($server_->{$object_property_}) ? json_serialize($server_->{$object_property_}) : NULL; $old_property_ = !is_null($old_property_) ? json_serialize($old_property_) : NULL; $SQL = SQL::getInstance(); if (!is_null($old_property_) && is_null($property_)) { $SQL->DoQuery('DELETE FROM #1 WHERE @2 = %3 AND @4 = %5 LIMIT 1', self::table_properties, 'property', $db_property_, 'server', $server_->id); } elseif (is_null($old_property_) && !is_null($property_)) { $SQL->DoQuery('INSERT INTO #1 (@2,@3,@4) VALUES(%5,%6,%7)', self::table_properties, 'server', 'property', 'value', $server_->id, $db_property_, $property_); } elseif ($old_property_ != $property_) { $SQL->DoQuery('UPDATE #1 SET @2=%3 WHERE @4 = %5 AND @6 = %7 LIMIT 1', self::table_properties, 'value', $property_, 'property', $db_property_, 'server', $server_->id); } return true; }