public function action_edit_field()
 {
     $field_id = $this->request->param('options');
     xml::to_XML(array('field' => array('@id' => $field_id, '$content' => User::get_data_field_name($field_id))), $this->xml_content);
     if (count($_POST) && isset($_POST['field_name'])) {
         $post = new Validation($_POST);
         $post->filter('trim');
         $post->rule('Valid::not_empty', 'field_name');
         if ($post->validate()) {
             $post_values = $post->as_array();
             if ($post_values['field_name'] != User::get_data_field_name($field_id) && !User::field_name_available($post_values['field_name'])) {
                 $post->add_error('field_name', 'User::field_name_available');
             }
         }
         // Retry
         if ($post->validate()) {
             $post_values = $post->as_array();
             User::update_field($field_id, $post_values['field_name']);
             $this->add_message('Field ' . $post_values['field_name'] . ' updated');
             $this->set_formdata(array('field_name' => $post_values['field_name']));
         } else {
             $this->add_error('Fix errors and try again');
             $this->add_form_errors($post->errors());
             $this->set_formdata(array_intersect_key($post->as_array(), $_POST));
         }
     } else {
         $this->set_formdata(array('field_name' => User::get_data_field_name($field_id)));
     }
 }
Beispiel #2
0
 public function action_entry()
 {
     // Set employees node
     $employees_node = $this->xml_content->appendChild($this->dom->createElement('employees'));
     $employees = array('0option' => array('@value' => '0', 'None'));
     $counter = 1;
     foreach (Employees::get() as $employee) {
         $employees[$counter . 'option'] = array('@value' => $employee['id'], $employee['lastname'] . ', ' . $employee['firstname']);
         $counter++;
     }
     xml::to_XML($employees, $employees_node);
     // This is for the select box
     if (count($_POST)) {
         $post = new Validation($_POST);
         $post->filter('trim');
         $post->filter('floatval', 'sum');
         $post->filter('floatval', 'vat');
         $post->rule('strtotime', 'accounting_date');
         $post->rule('strtotime', 'transfer_date');
         $post->rule('Valid::not_empty', 'description');
         if ($post->Validate()) {
             $new_transaction_data = array('accounting_date' => $post->get('accounting_date'), 'transfer_date' => $post->get('transfer_date'), 'description' => $post->get('description'), 'journal_id' => $post->get('journal_id'), 'vat' => $post->get('vat'), 'sum' => $post->get('sum'), 'employee_id' => $post->get('employee_id'));
             if (!isset($_GET['id'])) {
                 $transaction = new Transaction(NULL, $new_transaction_data);
                 $this->add_message('Transaction ' . $transaction->get_id() . ' added');
             } else {
                 $transaction = new Transaction($_GET['id']);
                 $transaction->set($new_transaction_data);
                 $this->add_message('Transaction ' . $transaction->get_id() . ' updated');
                 $this->set_formdata($transaction->get());
             }
         } else {
             $this->add_form_errors($post->errors());
             $this->set_formdata($post->as_array());
         }
     } elseif (isset($_GET['id'])) {
         $transaction = new Transaction($_GET['id']);
         $this->set_formdata($transaction->get());
     } else {
         $this->set_formdata(array('accounting_date' => date('Y-m-d', time()), 'transfer_date' => date('Y-m-d', time())));
     }
 }
 public function action_do()
 {
     if (count($_POST) && isset($_POST['username']) && isset($_POST['password'])) {
         Session::instance();
         $post = new Validation($_POST);
         $post->filter('trim');
         $post->filter('strtolower', 'username');
         // Usename should always be lower case
         $post_values = $post->as_array();
         $user = new User(FALSE, $post_values['username'], $post_values['password']);
         if ($user->logged_in() && $user->get_user_data('role') && array_intersect($user->get_role(), User::get_roles())) {
             // The user logged in correctly, and got the role "admin". All good
             $this->redirect('/admin');
         } elseif (!$user->logged_in()) {
             $_SESSION['modules']['pajas']['error'] = 'Wrong username or password';
         } elseif (!$user->get_user_data('role') || !in_array('admin', $user->get_user_data('role'))) {
             $_SESSION['modules']['pajas']['error'] = 'You are not authorized';
         } else {
             $_SESSION['modules']['pajas']['error'] = 'Unknown error';
         }
     }
     $this->redirect();
 }
Beispiel #4
0
 public function action_edit_customer()
 {
     $customer_id = $this->request->param('options');
     $customer_model = new Customer($customer_id);
     xml::to_XML(array('customer' => $customer_model->get()), $this->xml_content, NULL, 'id');
     if (count($_POST)) {
         $post = new Validation($_POST);
         $post->filter('trim');
         if ($post->validate()) {
             $customer_model->set($post->as_array());
             $this->add_message('Customer "' . $post->get('name') . '" updated');
         }
     }
     $this->set_formdata($customer_model->get());
 }
 public function action_edit_content()
 {
     $id = $this->request->param('options');
     $content = new Content_Content($id);
     if ($content->get_content_id()) {
         $this->xml_content->appendChild($this->dom->createElement('content_id', $id));
         if (count($_POST)) {
             $post = new Validation($_POST);
             $post->filter('trim');
             $post_values = $post->as_array();
             $tags = array();
             foreach ($post_values['tag'] as $nr => $tag_name) {
                 if ($tag_name) {
                     if (!isset($tags[$tag_name])) {
                         $tags[$tag_name] = array();
                     }
                     $tags[$tag_name][] = $post_values['tag_value'][$nr];
                 }
             }
             $content->update_content($post_values['content'], $tags);
             $this->add_message('Content #' . $id . ' updated');
         }
         $content_node = $this->xml_content->appendChild($this->dom->createElement('content'));
         $content_node->appendChild($this->dom->createTextNode($content->get_content()));
         $tags_node = $this->xml_content->appendChild($this->dom->createElement('tags'));
         foreach ($content->get_tags() as $tag) {
             if (!$tag['values']) {
                 $tag_node = $tags_node->appendChild($this->dom->createElement('tag'));
                 $tag_node->setAttribute('name', $tag['name']);
             } else {
                 foreach ($tag['values'] as $tag_value) {
                     $tag_node = $tags_node->appendChild($this->dom->createElement('tag', $tag_value));
                     $tag_node->setAttribute('name', $tag['name']);
                 }
             }
         }
     } else {
         $this->redirect();
     }
 }
 /**
  * Edit Tags
  * if id is set, instanciate an edit function
  * if not instanciate an add tag function.
  */
 public function action_role()
 {
     $this->xml_content_types = $this->xml_content->appendChild($this->dom->createElement('roles'));
     xml::to_XML(Uvtag::get_tags(), $this->xml_content_types, 'role');
     if (!empty($_POST)) {
         $post = new Validation($_POST);
         $post->filter('trim');
         $post->rule('Valid::not_empty', 'role');
         $post->rule('Valid::not_empty', 'uri');
         if (isset($role)) {
             $tag->update($post->as_array());
             $this->add_message('Role name updated');
         } else {
             if (Uvtag::add($post->get('role'), $post->get('uri'))) {
                 $this->add_message('Role "' . $post->get('name') . '" was added');
             } else {
                 $this->add_message('Role "' . $post->get('name') . '" could not be added');
             }
         }
     } elseif (isset($tag)) {
         // Set the form input to the tag name.
         $this->set_formdata($tag->get());
     }
 }
Beispiel #7
0
 public function action_employee()
 {
     $statuses = array('0option' => array('@value' => 'active', '$content' => 'Active'), '1option' => array('@value' => 'inactive', '$content' => 'Inactive'));
     xml::to_XML($statuses, $this->xml_content->appendChild($this->dom->createElement('statuses')));
     if (isset($_GET['id'])) {
         $employee = new Employee($_GET['id']);
         if (count($_POST)) {
             $post = new Validation($_POST);
             $post->filter('trim');
             $employee->set($post->as_array());
             $this->add_message('Employee ' . $_GET['id'] . ' information updated');
         }
         $this->set_formdata($employee->get());
         xml::to_XML(array('statuses' => array('1option' => array('@value' => 'active', 'Active'), '2option' => array('@value' => 'inactive', 'Inactive'))), $this->xml_content);
         xml::to_XML($employee->get(), $this->xml_content->appendChild($this->dom->createElement('employee')), NULL, 'id');
     } elseif (count($_POST)) {
         $post = new Validation($_POST);
         $post->filter('trim');
         $employee_id = Employee::new_employee($post->as_array());
         $this->add_message($post->get('firstname') . ' (ID: ' . $employee_id . ') was added as employee');
     } else {
         $this->redirect();
     }
 }
 public function action_edit_page()
 {
     $id = $this->request->param('options');
     $content_page = new Content_Page($id);
     if ($content_page->get_page_id()) {
         $this->xml_content_page = $this->xml_content->appendChild($this->dom->createElement('page'));
         // Get all tags associated with pages and images
         $this->xml_content_tags = $this->xml_content->appendChild($this->dom->createElement('tags'));
         $tags = array();
         foreach (Content_Page::get_tags() as $tag) {
             $tags[] = $tag;
         }
         foreach (Content_Image::get_tags() as $tag) {
             foreach ($tags as $tag_to_check) {
                 if ($tag_to_check['name'] == $tag['name']) {
                     break 2;
                 }
             }
             $tags[] = $tag;
         }
         foreach ($tags as $tag) {
             $tag_node = $this->xml_content_tags->appendChild($this->dom->createElement('tag', $tag['name']));
             $tag_node->setAttribute('id', $tag['id']);
         }
         if (count($_POST) && isset($_POST['URI']) && isset($_POST['name'])) {
             if ($_POST['URI'] == '') {
                 $_POST['URI'] = $_POST['name'];
             }
             $_POST['URI'] = URL::title($_POST['URI'], '-', TRUE);
             $post = new Validation($_POST);
             $post->filter('trim');
             $post->rule('Valid::not_empty', 'name');
             if ($post->validate()) {
                 $post_values = $post->as_array();
                 $current_page_data = $content_page->get_page_data();
                 if ($post_values['name'] != $current_page_data['name'] && !Content_Page::page_name_available($post_values['name'])) {
                     $post->add_error('name', 'Content_Page::page_name_available');
                 }
                 if ($post_values['URI'] != $current_page_data['URI'] && !Content_Page::page_URI_available($post_values['URI'])) {
                     $post->add_error('URI', 'Content_Page::page_URI_available');
                 }
             }
             // Retry
             if ($post->validate()) {
                 $tags = array();
                 foreach ($post_values['template_position'] as $nr => $template_position) {
                     if ($post_values['tag_id'][$nr] > 0) {
                         if (!isset($tags[$template_position])) {
                             $tags[$template_position] = array();
                         }
                         $tags[$template_position][] = $post_values['tag_id'][$nr];
                     }
                 }
                 $content_page->update_page_data($post_values['name'], $post_values['URI'], $tags);
                 $this->add_message('Page "' . $post_values['name'] . '" updated');
                 $page_data = $content_page->get_page_data();
                 unset($page_data['tag_ids']);
                 $this->set_formdata($page_data);
             } else {
                 $this->add_error('Fix errors and try again');
                 $this->add_form_errors($post->errors());
                 // Fix template position data
                 $tmp_node = $this->xml_content->appendChild($this->dom->createElement('tmp'));
                 foreach ($post_values['template_position'] as $nr => $template_position) {
                     $template_field_node = $tmp_node->appendChild($this->dom->createElement('template_field'));
                     $template_field_node->setAttribute('id', $template_position);
                     if ($post_values['tag_id'][$nr] > 0) {
                         $tag_node = $template_field_node->appendChild($this->dom->createElement('tag'));
                         $tag_node->setAttribute('id', $post_values['tag_id'][$nr]);
                     }
                 }
                 unset($post_values['template_position'], $post_values['tag_id']);
                 $this->set_formdata($post_values);
             }
         } else {
             $page_data = $content_page->get_page_data();
             unset($page_data['tag_ids']);
             $this->set_formdata($page_data);
         }
         /**
          * Put the page data to the XML
          *
          */
         $page_data = $content_page->get_page_data();
         $page_data['template_fields'] = array();
         foreach ($page_data['tag_ids'] as $template_field_id => $tag_ids) {
             $page_data['template_fields'][$template_field_id . 'template_field'] = array('@id' => $template_field_id);
             foreach ($tag_ids as $tag_id) {
                 $page_data['template_fields'][$template_field_id . 'template_field'][$tag_id . 'tag'] = array('@id' => $tag_id);
             }
         }
         // Unset this, or it will cludge our XML
         unset($page_data['tag_ids']);
         // Set the page data to the page node
         xml::to_XML($page_data, $this->xml_content_page, NULL, 'id');
     } else {
         $this->redirect();
     }
 }
 public function action_user()
 {
     $formdata = array();
     if (isset($_GET['id'])) {
         $user = new User($_GET['id'], FALSE, FALSE, 'default', FALSE);
         if (!$user->logged_in()) {
             $this->redirect();
         }
     }
     $this->list_available_data_fields();
     if (!empty($_POST) && isset($_POST['username']) && isset($_POST['password'])) {
         $post = new Validation($_POST);
         $post->filter('trim');
         $post->filter('strtolower', 'username');
         $post->rule('Valid::not_empty', 'username');
         if (isset($user)) {
             if ($_POST['username'] != $user->get_username()) {
                 $post->rule('User::username_available', 'username');
             }
         } else {
             $post->rule('User::username_available', 'username');
         }
         if (!isset($user)) {
             $post->rule('Valid::not_empty', 'password');
         }
         if (isset($_POST['do_add_field'])) {
             // Add another user data field and save no data, but repopulate the form fields
             if (!isset($_SESSION['detail_fields'])) {
                 $_SESSION['detail_fields'] = array();
             }
             $_SESSION['detail_fields'][] = $_POST['add_field'];
             // Reconstruct the form data to repopulate the form
             $formdata = array();
             $counter = 0;
             $post_values = $post->as_array();
             foreach ($post_values as $field => $data) {
                 if (substr($field, 0, 8) == 'fieldid_') {
                     foreach ($data as $data_piece) {
                         $counter++;
                         $formdata['field_' . substr($field, 8) . '_' . $counter] = trim($data_piece);
                     }
                 } elseif ($field == 'username') {
                     $formdata[$field] = $post_values[$field];
                 }
             }
         } else {
             // Check for form errors
             if ($post->validate()) {
                 // No form errors, add the user!
                 $post_values = $post->as_array();
                 // Erase the empty data fields
                 foreach ($post_values as $key => $value) {
                     if (substr($key, 0, 8) == 'fieldid_' && is_array($value)) {
                         foreach ($value as $nr => $value_piece) {
                             if ($value_piece == '') {
                                 unset($post_values[$key][$nr]);
                             }
                         }
                     }
                 }
                 // Organize the field data and set the session fields
                 $fields = $_SESSION['detail_fields'] = array();
                 foreach ($post_values as $key => $value) {
                     if (substr($key, 0, 6) == 'field_') {
                         list($foobar, $field_id, $field_nr) = explode('_', $key);
                         $fields[User::get_data_field_name($field_id)][] = $value;
                     }
                 }
                 if (!isset($_GET['id'])) {
                     // Actually add the user
                     User::new_user($post_values['username'], $post_values['password'], $fields);
                     $this->add_message('User ' . $post_values['username'] . ' added');
                 } elseif (isset($user)) {
                     $user->set_user_data(array_merge($fields, array('username' => $post_values['username'], 'password' => $post_values['password'])), TRUE);
                     $this->add_message('User data saved');
                 }
             } else {
                 // Form errors detected!
                 $this->add_error('Fix errors and try again');
                 $this->add_form_errors($post->errors());
                 $formdata = array();
                 $counter = 0;
                 $post_values = $post->as_array();
                 foreach ($post_values as $field => $data) {
                     if (substr($field, 0, 8) == 'fieldid_') {
                         foreach ($data as $data_piece) {
                             $counter++;
                             $formdata['field_' . substr($field, 8) . '_' . $counter] = trim($data_piece);
                         }
                     } elseif ($field == 'username') {
                         $formdata[$field] = $post_values[$field];
                     }
                 }
             }
         }
     }
     if (isset($user)) {
         $formdata = array('username' => $user->get_username());
         $counter = 0;
         foreach ($user->get_user_data() as $field => $data) {
             foreach ($data as $data_piece) {
                 $counter++;
                 $formdata['field_' . User::get_data_field_id($field) . '_' . $counter] = $data_piece;
             }
         }
     }
     if (!empty($_SESSION['detail_fields'])) {
         foreach ($_SESSION['detail_fields'] as $field_id) {
             $counter = 1;
             while (isset($formdata['field_' . $field_id . '_' . $counter])) {
                 $counter++;
             }
             $formdata['field_' . $field_id . '_' . $counter] = '';
         }
     }
     $this->set_formdata($formdata);
 }
Beispiel #10
0
 public function action_bill()
 {
     $this->xml_content_customers = $this->xml_content->appendChild($this->dom->createElement('customers'));
     xml::to_XML(Customers::get_customers(), $this->xml_content_customers, 'customer', 'id');
     $template = array();
     foreach (glob(MODPATH . 'larvconomy/xsl/bills/*') as $file) {
         $file_paths = explode('/', $file);
         $template_file = explode('.', end($file_paths));
         $template[] = reset($template_file);
     }
     $this->xml_content_bill_template = $this->xml_content->appendChild($this->dom->createElement('templates'));
     xml::to_XML($template, $this->xml_content_bill_template, 'template');
     if (!isset($_SESSION['bills']['items'])) {
         $_SESSION['bills']['items']['1item'] = 1;
     }
     if (count($_POST)) {
         $post = new Validation($_POST);
         $post->filter('trim');
         $post_array = $post->as_array();
         if (isset($post_array['add_item'])) {
             $_SESSION['bills']['items'][count($_SESSION['bills']['items']) + 1 . 'item'] = count($_SESSION['bills']['items']) + 1;
             $this->set_formdata($post_array);
         } else {
             $items = array();
             $sum = 0;
             $vat_sum = 0;
             foreach ($_SESSION['bills']['items'] as $item_nr) {
                 $item = array('artnr' => $post->get('artnr_item_' . $item_nr), 'spec' => $post->get('spec_item_' . $item_nr), 'price' => (double) $post->get('price_item_' . $item_nr), 'qty' => (double) $post->get('qty_item_' . $item_nr), 'delivery_date' => date('Y-m-d', time()));
                 if ($item != array('artnr' => '', 'spec' => '', 'price' => 0, 'qty' => 0, 'delivery_date' => date('Y-m-d', time()))) {
                     $items[] = $item;
                     $sum += $item['qty'] * $item['price'] * 1.25;
                     $vat_sum += $item['qty'] * $item['price'] * 0.25;
                 }
             }
             if (count($items) && $post->validate()) {
                 $bill_id = Bill::new_bill($post->get('customer_id'), strtotime($post->get('due_date')), $post->get('contact'), $items, $post->get('comment'), $post->get('template'), $post->get('mail_body'));
                 $this->add_message('Created bill nr ' . $bill_id);
                 unset($_SESSION['bills']['items']);
                 // Create the transaction
                 $data = array('accounting_date' => date('Y-m-d', time()), 'transfer_date' => '0000-00-00', 'description' => 'Bill ' . $bill_id, 'vat' => $vat_sum, 'sum' => $sum, 'employee_id' => NULL, 'journal_id' => NULL);
                 $transaction = new Transaction(NULL, $data);
                 // End of Create the transaction
                 // Set new default due date
                 $this->set_formdata(array('due_date' => date('Y-m-d', time() + 20 * 24 * 60 * 60)));
                 // Make the PDF
                 if (Kohana::$config->load('larv.htpassword.password') && Kohana::$config->load('larv.htpassword.username')) {
                     shell_exec('wkhtmltopdf --ignore-load-errors --username ' . Kohana::$config->load('larv.htpassword.username') . ' --password ' . Kohana::$config->load('larv.htpassword.password') . ' "' . $_SERVER['SERVER_NAME'] . URL::site('bill?billnr=' . $bill_id . '&template=' . $post->get('template')) . '" "' . APPPATH . 'user_content/pdf/bill_' . $bill_id . '.pdf"');
                 } else {
                     shell_exec('wkhtmltopdf --ignore-load-errors "' . $_SERVER['SERVER_NAME'] . URL::site('bill?billnr=' . $bill_id . '&template=' . $post->get('template')) . '" "' . APPPATH . 'user_content/pdf/bill_' . $bill_id . '.pdf"');
                 }
                 if (isset($_FILES)) {
                     Bill::upload($_FILES, 'attachments/' . $bill_id);
                 }
             } else {
                 $this->add_error('Not enough data');
                 $post->set('due_date', date('Y-m-d', strtotime($post->get('due_date'))));
                 $post->set('mail_body', Kohana::$config->load('larv.email.bill_message'));
                 $this->set_formdata($post->as_array());
             }
         }
     } else {
         $this->set_formdata(array('due_date' => date('Y-m-d', time() + 20 * 24 * 60 * 60), 'mail_body' => Kohana::$config->load('larv.email.bill_message')));
     }
     xml::to_XML($_SESSION['bills'], $this->xml_content);
 }
Beispiel #11
0
 public function action_payout()
 {
     // Set employees node
     $employees_node = $this->xml_content->appendChild($this->dom->createElement('employees'));
     $employees = array();
     $counter = 0;
     $employees_from_model = Employees::get();
     foreach ($employees_from_model as $employee) {
         $employees[$counter . 'option'] = array('@value' => $employee['id'], $employee['lastname'] . ', ' . $employee['firstname']);
         $counter++;
     }
     xml::to_XML($employees, $employees_node);
     // This is for the select box
     xml::to_XML($employees_from_model, $employees_node, 'employee', 'id');
     if (isset($_GET['id'])) {
         if (count($_POST)) {
             $post = new Validation($_POST);
             $post->filter('trim');
             $salary->set($post->as_array());
         }
         $this->set_formdata($salary->get());
         xml::to_XML(array('statuses' => array('1option' => array('@value' => 'active', 'Active'), '2option' => array('@value' => 'inactive', 'Inactive'))), $this->xml_content);
         xml::to_XML($employee->get(), $this->xml_content->appendChild($this->dom->createElement('employee')), NULL, 'id');
         $this->add_message('Employee ' . $_GET['id'] . ' information updated');
     } elseif (count($_POST)) {
         // Add new payout
         $post = new Validation($_POST);
         $post->filter('trim');
         $post->rule('Valid::digit', 'amount');
         $post->rule('strtotime', 'date');
         if ($post->validate()) {
             $post_array = $post->as_array();
             $transaction_data = array('accounting_date' => date('Y-m-d', strtotime($post_array['date'])), 'transfer_date' => date('Y-m-d', strtotime($post_array['date'])), 'description' => 'Salary payout', 'journal_id' => NULL, 'vat' => 0, 'sum' => -$post_array['amount'], 'employee_id' => $post_array['employee_id']);
             $transaction = new Transaction(NULL, $transaction_data);
             if ($id = $transaction->get_id()) {
                 $this->add_message('New transaction added (ID ' . $id . ')');
             } else {
                 $this->add_error('Something f****d up');
             }
         } else {
             $this->set_formdata($post->as_array());
             $errors = $post->errors();
             $this->add_form_errors($errors);
             if (isset($errors['date'])) {
                 $this->add_form_errors(array('date' => 'Invalid date format'));
             }
             if (isset($errors['amount'])) {
                 $this->add_form_errors(array('amount' => 'Must be numbers ONLY'));
             }
         }
     }
 }
 public function action_edit_image()
 {
     $name = $this->request->param('options');
     if ($content_image = new Content_Image($name)) {
         $short_name = substr($name, 0, strlen($name) - 4);
         $this->xml_content_image = $this->xml_content->appendChild($this->dom->createElement('image'));
         $this->xml_content_image->setAttribute('name', $name);
         $this->xml_content_image->appendChild($this->dom->createElement('URL', 'user_content/images/' . $name));
         $tags_node = $this->xml_content_image->appendChild($this->dom->createElement('tags'));
         if (count($_POST)) {
             $_POST['name'] = URL::title($_POST['name'], '-', TRUE);
             $post = new Validation($_POST);
             $post->filter('trim');
             $post->rule('Valid::not_empty', 'name');
             $form_data = $post->as_array();
             if ($form_data['name'] != $short_name) {
                 $post->rule('Content_Image::image_name_available', 'name');
             }
             // Check for form errors
             if ($post->validate()) {
                 // No form errors, edit image
                 $new_image_data = array();
                 foreach ($form_data['tag'] as $nr => $tag_name) {
                     if (!isset($new_image_data[$tag_name])) {
                         $new_image_data[$tag_name] = array();
                     }
                     $new_image_data[$tag_name][] = $form_data['tag_value'][$nr];
                 }
                 $content_image->set_data(array_merge($new_image_data, array('name' => $form_data['name'] . '.jpg')));
                 if ($form_data['name'] != $short_name) {
                     // If the image name have changed, we need to change the URL also
                     // Save the message for the new URL
                     $_SESSION['content']['image']['message'] = 'Image data saved';
                     // Redirect to the new name
                     $this->redirect('/admin/images/edit_image/' . $form_data['name'] . '.jpg');
                 }
                 $this->add_message('Image data saved');
                 $this->set_formdata(array('name' => $short_name));
                 $image_data = $content_image->get_data();
                 foreach ($image_data as $tag_name => $tag_values) {
                     foreach ($tag_values as $tag_value) {
                         $tag_node = $tags_node->appendChild($this->dom->createElement('tag', $tag_value));
                         $tag_node->setAttribute('name', $tag_name);
                     }
                     if (!count($tag_values)) {
                         $tag_node = $tags_node->appendChild($this->dom->createElement('tag'));
                         $tag_node->setAttribute('name', $tag_name);
                     }
                 }
             } else {
                 // Something is wrong. Fill form with unsaved data and push error
                 $this->set_formdata(array('name' => $form_data['name']));
                 foreach ($form_data['tag'] as $nr => $tag_name) {
                     if ($tag_name != '') {
                         $tag_node = $tags_node->appendChild($this->dom->createElement('tag', $form_data['tag_value'][$nr]));
                         $tag_node->setAttribute('name', $tag_name);
                     }
                 }
                 $this->add_form_errors($post->errors());
             }
         } else {
             $this->set_formdata(array('name' => $short_name));
             $image_data = $content_image->get_data();
             foreach ($image_data as $tag_name => $tag_values) {
                 foreach ($tag_values as $tag_value) {
                     $tag_node = $tags_node->appendChild($this->dom->createElement('tag', $tag_value));
                     $tag_node->setAttribute('name', $tag_name);
                 }
                 if (!count($tag_values)) {
                     $tag_node = $tags_node->appendChild($this->dom->createElement('tag'));
                     $tag_node->setAttribute('name', $tag_name);
                 }
             }
         }
         if (isset($_SESSION['content']['image']['message'])) {
             $this->add_message($_SESSION['content']['image']['message']);
             unset($_SESSION['content']['image']['message']);
         }
     } else {
         $this->redirect();
     }
 }