/** * @internal Renames a term. * * Sometimes you may want to correct a terms name, so use this one. * @param string $term The original term * @param string $new_term The new term name * @return void * @attribute[RequestParam('term','string')] * @attribute[RequestParam('new_term','string',false)] */ function Rename($term, $new_term) { if (!$new_term) { $dlg = new uiDialog('Rename term'); $dlg->content("Enter new term: "); $ti = $dlg->content(new TextInput($term)); $dlg->AddButton('Rename', "function(){ wdf.controller.post('Rename',{term:'{$term}',new_term:\$('#{$ti->id}').val()}); }"); $dlg->AddCloseButton('Cancel'); return $dlg; } $this->ds->ExecuteSql("UPDATE wdf_translations SET id=? WHERE id=?", array($new_term, $term)); return AjaxResponse::Redirect('TranslationAdmin', 'Translate', array('lang' => $_SESSION['trans_admin_lang'], 'offset' => $_SESSION['trans_admin_offset'], 'search' => $_SESSION['trans_admin_search'])); }
/** * @attribute[RequestParam('title','string',false)] * @attribute[RequestParam('tagline','string',false)] * @attribute[RequestParam('body','text',false)] * @attribute[RequestParam('price','double',false)] */ function AddProduct($title, $tagline, $body, $price) { $this->_login(); // require admin to be logged in // This is a quite simple condition: You MUST provide each of the variables if ($title && $tagline && $body && $price) { // store the uploaded image if present if (isset($_FILES['image']) && $_FILES['image']['name']) { $i = 1; $image = __DIR__ . '/../images/' . $_FILES['image']['name']; while (file_exists($image)) { $image = __DIR__ . '/../images/' . $i++ . '_' . $_FILES['image']['name']; } move_uploaded_file($_FILES['image']['tmp_name'], $image); $image = basename($image); } else { $image = ''; } // store the new product into the database $ds = model_datasource('system'); $ds->ExecuteSql("INSERT INTO products(title,tagline,body,image,price)VALUES(?,?,?,?,?)", array($title, $tagline, $body, $image, $price)); redirect('Admin'); } // create a dialog and put a template on it. $dlg = new uiDialog('Add product', array('width' => 600, 'height' => 450)); $dlg->content(Template::Make('admin_product_add')); $dlg->AddButton('Add product', "\$('#frm_add_product').submit()"); // frm_add_product is defined in the template $dlg->AddCloseButton("Cancel"); return $dlg; }