NaveenYadav Posted April 11, 2014 Share Posted April 11, 2014 Hello All, I want to add text-editor in my php file(Not in tpl file) without rendor form in Adminarea. So please help me out of this problem. Thanks Link to comment Share on other sites More sharing options...
NaveenYadav Posted April 12, 2014 Author Share Posted April 12, 2014 Any one help me............ Link to comment Share on other sites More sharing options...
vekia Posted April 12, 2014 Share Posted April 12, 2014 this php file is a part of ... ? and where you want to dispaly it? front offie? back office? Link to comment Share on other sites More sharing options...
NaveenYadav Posted April 15, 2014 Author Share Posted April 15, 2014 (edited) Hello Vekia, I have created a module and I want to add text-editor in module php file in Adminarea. And I am creating form in display() function. Here is my php file. <?phprequire_once (dirname(__file__) . '/prestashoptool.php');require_once (dirname(__file__) . '/classes/RowProduct.php');class AdminRowProduct extends AdminTab { public function __construct() { global $cookie; $cont = 'AdminRowProduct'; $tkn = Tools::getValue('token'); $this->ur = 'index.php?controller=' . $cont . '&token=' . $tkn; parent::__construct(); } public function display() { if (Tools::isSubmit('rowProduct')) { //echo "<pre>";print_r($_FILES);exit; //echo "<pre>";print_r($_POST);exit; if(empty($_POST['category'])) { //echo $errors == '' ? $this->displayConfirmation($this->l('Please Select Category.')) : $errors; echo '<div class="bootstrap"> <div class="alert alert-danger"> <button class="close" data-dismiss="alert" type="button">×</button> '.$this->l('Please Select Category ').' </div> </div>'; } else if(empty($_POST['name'])) { echo '<div class="bootstrap"> <div class="alert alert-danger"> <button class="close" data-dismiss="alert" type="button">×</button> '.$this->l('Please Fill Product Name').' </div> </div>'; } else if(empty($_POST['price'])) { echo '<div class="bootstrap"> <div class="alert alert-danger"> <button class="close" data-dismiss="alert" type="button">×</button> '.$this->l('Please Fill product Price ').' </div> </div>'; } else if(!is_numeric($_POST['price'])) { echo '<div class="bootstrap"> <div class="alert alert-danger"> <button class="close" data-dismiss="alert" type="button">×</button> '.$this->l('Please Fill Numeric Value').' </div> </div>'; } else if(empty($_POST['long_desc'])) { echo '<div class="bootstrap"> <div class="alert alert-danger"> <button class="close" data-dismiss="alert" type="button">×</button> '.$this->l('Please Select Category ').' </div> </div>'; echo '<div class="error">'.$this->l('Please Fill Long Description ').'</div>'; } else if(empty($_POST['short_desc'])) { echo '<div class="bootstrap"> <div class="alert alert-danger"> <button class="close" data-dismiss="alert" type="button">×</button> '.$this->l('Please Fill Short Description').' </div> </div>'; } else if(empty($_POST['default'])) { echo '<div class="bootstrap"> <div class="alert alert-danger"> <button class="close" data-dismiss="alert" type="button">×</button> '.$this->l('Please Select Default View').' </div> </div>'; } else{ $res = $this->saveRowProduct($_POST); header('Location: '.$this->ur); } } if (Tools::isSubmit('edit')) { $res = $this->editRowProduct(); // header('Location: '.$this->ur); } if (Tools::isSubmit('delete')) { $this->deleteRowProduct(Tools::getValue('id_row_product')); header('Location: '.$this->ur); } $html = ''; $html = '<script type="text/javascript" src="' . _MODULE_DIR_ . 'prestashoptool/prestashoptool.js"></script>'; $row = new RowProduct(); // $html .= $row->getTopHeader('Manage Row Product',$this->ur); // $html .='<script type="text/javascript" src="'..'designertool/jquery-1.4.2.min.js"></script>'; $catoption = $row->getProductCategory($this->context->language->id); // print_r($catoption);exit; $html .= '<div class="bootstrap"><div class="panel" style="margin-bottom:2%"> <h3 class="tab"> '.$this->l('Add/Edit Product').' </h3> <table style="" class="table" id=""> <thead> <tr> <th><span class="title_box active">' . $this->l('ID') . '</span></th> <th><span class="title_box active">' . $this->l('Product Name') . '</span></th> <th><span class="title_box active">' . $this->l('Price') . '</span></th> <th><span class="title_box active">' . $this->l('status') . '</span></th> <th><span class="title_box active">' . $this->l('Action') . '</span></th> </tr> </thead>'; $html .= $this->getRowData(); $html .= '</table></div>'; $html .= '<div class="panel"> <form action="" method="post" enctype="multipart/form-data" name="product_dis" class="form-horizontal col-lg-10"> <h3 class="tab"> '.$this->l('Add/Edit Product').' </h3> <input type="hidden" name="id_row_product" value="' . (!empty($res[0]['id_row_product']) ? $res[0]['id_row_product'] : '') . '" />'; $html .='<div class="form-group"> <label class="control-label col-lg-3" for="name"> <span class="label-tooltip" data-toggle="tooltip"> '.$this->l('Select Category:').' </span> </label> <div class="col-lg-3"> <select name="category"> <option value="">Select Please</option>'; if (!empty($res[0]['id_category'])) $cat_id = $res[0]['id_category']; else $cat_id = $_POST['category']; foreach ($catoption as $k => $v) { $html .= '<option value="' . $v['id_product_category'] . '" ' . ($cat_id == $v['id_product_category'] ? 'selected' : '') . '>' . $v['name'] . '</option>'; } $html .= '</select> </div> </div>'; $html .='<div class="form-group"> <label class="control-label col-lg-3" for="name"> <span class="label-tooltip" data-toggle="tooltip"> '.$this->l('product Name:').' </span> </label> <div class="col-lg-5"> <input type="text" id="name" name="name" value="' . (!empty($res[0]['productname']) ? $res[0]['productname'] : $_POST['name']) . '" /> </div> </div>'; $html .='<div class="form-group"> <label class="control-label col-lg-3" for="name"> <span class="label-tooltip" data-toggle="tooltip"> '.$this->l('Price:').' </span> </label> <div class="col-lg-5"> <input type="text" id="price" name="price" value="' . (!empty($res[0]['price']) ? $res[0]['price'] : $_POST['price']) . '" /> </div> </div>'; $html .='<div class="form-group"> <label class="control-label col-lg-3" for="name"> <span class="label-tooltip" data-toggle="tooltip"> '.$this->l('Short description:').' </span> </label> <div class="col-lg-5"> <textarea name="short_desc" class="autoload_rte" rows="5">' . (!empty($res[0]['short_description']) ? $res[0]['short_description'] : $_POST['short_description']) . '</textarea> </div> </div>'; $html .='<div class="form-group"> <label class="control-label col-lg-3" for="name"> <span class="label-tooltip" data-toggle="tooltip"> '.$this->l('Long Description:').' </span> </label> <div class="col-lg-5"> <textarea name="long_desc" class="autoload_rte" rows="5">' . (!empty($res[0]['long_description']) ? $res[0]['long_description'] : $_POST['long_description']) . '</textarea> </div> </div>'; $html .='<div class="form-group"> <label class="control-label col-lg-3" for="name"> <span class="label-tooltip" data-toggle="tooltip"> '.$this->l('Image:').' </span> </label> <div class="col-lg-5"><input type="file" name="image" id="productimage" /> <div class="image">' . (!empty($res[0]['image']) ? '<img src="' . _MODULE_DIR_ . 'prestashoptool/image/productimage/thumb/' . $res[0]['image'] . '" />' : '') . '</div> </div> </div>'; $r = $this->getView($this->context->language->id); // echo "<pre>";print_r($res); $i = 0; foreach ($r as $k => $v) { $html .= '<div class="form-group"> <label class="control-label col-lg-3"> <span class="label-tooltip" data-toggle="tooltip">'.$v['name'].'</span></label> <div class="col-lg-9"> <span class="switch prestashop-switch fixed-width-lg"> <input id="default_on" type="radio" ' . ($res[0]['isDefault'] == $v['id_product_view'] ? 'checked' : '') . ' value="' . $v['id_product_view'] . '" name="default" onclick="toggleDraftWarning(false);showOptions(true);showRedirectProductOptions(false);"> <label class="radioCheck" for="default_on" style="width: 50% !important;"> Yes </label> <input id="default_off" ' . ($res[0]['isDefault'] == 0 ? 'checked' : '') . ' type="radio" value="0" name="default" onclick="toggleDraftWarning(true);showOptions(false);showRedirectProductOptions(true);"> <label class="radioCheck" for="default_off" style="width: 50% !important;"> No </label> <a class="slide-button btn"></a> </span> </div></div> <div class="form-group"> <label class="control-label col-lg-3"></label> <div class="col-lg-5"> Outline : <input type="file" name="viewimage1_' . $v['id_product_view'] . '" id="viewimage1_' . $v['id_product_view'] . '" /> <div class="image">' . (!empty($res[0]['view'][$i]['view_image1']) ? '<img src="' . _MODULE_DIR_ . 'prestashoptool/image/view1/thumb/' . $res[0]['view'][$i]['view_image1'] . '" />' : '') . '</div> </br> <input type="hidden" name="view_image1_'.$v['id_product_view'].'" value="'.$res[0]['view'][$i]['view_image1'].'" /> InLine : <input type="file" name="viewimage2_' . $v['id_product_view'] . '" id="viewimage2_' . $v['id_product_view'] . '" /> <div class="image">' . (!empty($res[0]['view'][$i]['view_image2']) ? '<img src="' . _MODULE_DIR_ . 'prestashoptool/image/view2/thumb/' . $res[0]['view'][$i]['view_image2'] . '" />' : '') . '</div> <input type="hidden" name="view_image2_'.$v['id_product_view'].'" value="'.$res[0]['view'][$i]['view_image2'].'" /></div></div>'; $i = $i + 1; //$html .= $v['name']; } $html .='<div class="form-group"> <label class="control-label col-lg-3"> <span class="label-tooltip" data-toggle="tooltip">'.$this->l('Enabled').'</span></label> <div class="col-lg-9"> <span class="switch prestashop-switch fixed-width-lg"> <input id="active_on" type="radio" ' . ($res[0]['active'] == 1 ? 'checked' : '') . ' value="1" name="active" onclick="toggleDraftWarning(false);showOptions(true);showRedirectProductOptions(false);"> <label class="radioCheck" for="active_on" style="width: 50% !important;"> Yes </label> <input id="active_off" ' . ($res[0]['active'] == 0 ? 'checked' : '') . ' type="radio" value="0" name="active" onclick="toggleDraftWarning(true);showOptions(false);showRedirectProductOptions(true);"> <label class="radioCheck" for="active_off" style="width: 50% !important;"> No </label> <a class="slide-button btn"></a> </span> </div> </div>'; $html .=' <div> <input type="hidden" name="viewimagecount" value="' . count($r) . '" /> <button type="submit" name="rowProduct"><i class="process-icon-save"></i> '.$this->l('Save').'</button> </div> </div></form></div></div>'; echo $html; } public function getView($id_lang) { return Db::getInstance()->ExecuteS(' SELECT pv.id_product_view,pvl.name FROM ' . _DB_PREFIX_ . 'product_view AS pv INNER JOIN ' . _DB_PREFIX_ . 'product_view_lang AS pvl ON (pv.id_product_view = pvl.id_product_view) WHERE pvl.id_lang=' . $id_lang . ' AND pv.active = 1' ); } public function saveRowProduct($post) { if ($_FILES['image']['name']) { $filename = $_FILES['image']['name']; list($name, $extension) = explode(".", $filename); $extension = strtolower($extension); $image_name = date("Ymdhis") . time() . rand() . '.' . $extension; $target = $_SERVER['DOCUMENT_ROOT'] . _MODULE_DIR_ . 'prestashoptool/image/productimage/original/' . $image_name; $filestatus = move_uploaded_file($_FILES['image']['tmp_name'], $target); //============== creation thumb rawproduct image ===================== $thumbPath = $_SERVER['DOCUMENT_ROOT'] . _MODULE_DIR_ . 'prestashoptool/image/productimage/thumb/' . $image_name; $lsp = $this->getImageRatio(100, 100, $target); exec(_PS_IMAGE_MAGICK_ . " $target -resize $lsp $thumbPath"); } else { $image_name = ""; } if (empty($post['id_row_product'])) { Db::getInstance()->autoExecute( _DB_PREFIX_ . 'row_product', array( 'id_category' => $post['category'], //'id_subcategory' => $post['subcategory'], 'productname' => $post['name'], 'price' => $post['price'], 'long_description' => $post['long_desc'], 'short_description' => $post['short_desc'], 'image' => $image_name, 'isDefault' => $post['default'], 'active' => $post['active'] ), 'INSERT' ); $last_id = Db::getInstance()->Insert_ID(); } else { //print_r($_POST);exit; Db::getInstance()->executeS(' UPDATE ' . _DB_PREFIX_ . 'row_product SET id_category=' . $post['category'] . ', productname="' . $post['name'] . '",price="' . $post['price'] . '",long_description="' . $post['long_desc'] . '", short_description="' . $post['short_desc'] . '",active=' . $post['active'] . ', isDefault="' . $post['default'] . '" '.(!empty($image_name)?',image="'.$image_name.'"':'').' WHERE id_row_product=' . (int) $post['id_row_product']); } $r = $this->getView($this->context->language->id); if (!empty($post['id_row_product'])) { $id_row_product = $post['id_row_product']; } else{ $id_row_product = $last_id; } // echo "<pre>";print_r($_FILES);exit; // echo 'DELETE FROM '._DB_PREFIX_.'view_image WHERE id_row_product ='.$post['id_row_product'];exit; Db::getInstance()->executeS('DELETE FROM '._DB_PREFIX_.'view_image WHERE id_row_product ='.$post['id_row_product']); foreach ($r as $key => $value) { list($name1, $extension1) = explode(".", $_FILES['viewimage1_' . $value['id_product_view']]['name']); if ($_FILES['viewimage1_' . $value['id_product_view']]['name']) { if( $extension1 == 'png'){ $filename = $_FILES['viewimage1_' . $value['id_product_view']]['name']; list($name, $extension) = explode(".", $filename); $extension = strtolower($extension); $image_name1 = 'viewimage1_' . $value['id_product_view'] . '_'.$id_row_product.'.' . $extension; $target = $_SERVER['DOCUMENT_ROOT'] . _MODULE_DIR_ . 'prestashoptool/image/view1/original/' . $image_name1; $filestatus = move_uploaded_file($_FILES['viewimage1_' . $value['id_product_view']]['tmp_name'], $target); //============== creation large and thumb rawproduct image ===================== $largePath = $_SERVER['DOCUMENT_ROOT'] . _MODULE_DIR_ . 'prestashoptool/image/view1/large/' . $image_name1; $lsp = $this->getImageRatio(500, 500, $target); exec(_PS_IMAGE_MAGICK_ . " $target -resize $lsp $largePath"); $thumbPath = $_SERVER['DOCUMENT_ROOT'] . _MODULE_DIR_ . 'prestashoptool/image/view1/thumb/' . $image_name1; $lsp = $this->getImageRatio(100, 100, $target); exec(_PS_IMAGE_MAGICK_ . " $target -resize $lsp $thumbPath"); }else{ echo '<div class="error">'.$this->l('Please upload only png images in OutLine').'</div>'; } } else { $image_name1 = $post['view_image1_'.$value['id_product_view']]; } list($name2, $extension2) = explode(".", $_FILES['viewimage2_' . $value['id_product_view']]['name']); if ($_FILES['viewimage2_' . $value['id_product_view']]['name']) { if($extension2 == 'png'){ $filename = $_FILES['viewimage2_' . $value['id_product_view']]['name']; list($name, $extension) = explode(".", $filename); $extension = strtolower($extension); $image_name2 = 'viewimage2_' . $value['id_product_view'] . '_'.$id_row_product.'.' . $extension; $target = $_SERVER['DOCUMENT_ROOT'] . _MODULE_DIR_ . 'prestashoptool/image/view2/original/' . $image_name2; $filestatus = move_uploaded_file($_FILES['viewimage2_' . $value['id_product_view']]['tmp_name'], $target); //============== creation large and thumb rawproduct image ===================== $largePath = $_SERVER['DOCUMENT_ROOT'] . _MODULE_DIR_ . 'prestashoptool/image/view2/large/' . $image_name2; $lsp = $this->getImageRatio(500, 500, $target); exec(_PS_IMAGE_MAGICK_ . " $target -resize $lsp $largePath"); $thumbPath = $_SERVER['DOCUMENT_ROOT'] . _MODULE_DIR_ . 'prestashoptool/image/view2/thumb/' . $image_name2; $lsp = $this->getImageRatio(100, 100, $target); exec(_PS_IMAGE_MAGICK_ . " $target -resize $lsp $thumbPath"); }else{ echo '<div class="error">'.$this->l('Please upload only png images in InLine').'</div>'; } } else { $image_name2 = $post['view_image2_'.$value['id_product_view']]; } if (!empty($post['id_row_product'])) { $id_row_product = $post['id_row_product']; } else{ $id_row_product = $last_id; } // $w = Db::getInstance()->executeS('SELECT id_row_product FROM '._DB_PREFIX_.'view_image WHERE id_row_product ='.$id_row_product); //if(!empty($w)) //echo $image_name1.'+++++++++'.$image_name2;exit; Db::getInstance()->autoExecute( _DB_PREFIX_ .'view_image', array( 'id_row_product' => $id_row_product, 'view_image1' => $image_name1, 'view_image2' => $image_name2, 'id_product_view' => $value['id_product_view'] ), 'INSERT' ); } } //======================= image ratio============================ function getImageRatio($ratioW, $ratioH, $imgPath) { $imageRatio = ''; list($width, $height) = @(getimagesize($imgPath)); if ($width > $ratioW && $height > $ratioH) { $imageRatio = $ratioW . 'x' . $ratioH; } else if ($width < $ratioW && $height > $ratioH) { $imageRatio = 'x' . $ratioH; } else if ($width > $ratioW && $height < $ratioH) { $imageRatio = $ratioW . 'x'; } else { $imageRatio = $width . 'x' . $height; } return $imageRatio; } public function getRowData() { $tableBlock = ''; $listBlock = $this->getData(NULL); //print_r($listBlock);exit; foreach ($listBlock as $listBlock) { $status = $listBlock['active'] == 1 ? 'yes' : 'no'; $tableBlock .= '<tr>'; $tableBlock .= '<td>' . $listBlock['id_row_product'] . '</td>'; $tableBlock .= '<td>' . $listBlock['productname'] . '</td>'; $tableBlock .= '<td>' . $listBlock['price'] . '</td>'; $tableBlock .= '<td>' . ($status == 'yes'?'<a class="list-action-enable action-enabled" href="javascript:void(0);"><i class="icon-check"></i></a>':'<a class="list-action-enable action-disabled" href="javascript:void(0);"><i class="icon-remove"></i></a>'). '</td>'; $tableBlock .= '<td> <form action="' . $_SERVER['REQUEST_URI'] . '" method="POST"> <input type="hidden" name="id_row_product" value="' . $listBlock['id_row_product'] . '" /> <button name="edit" class="button"><img src="../img/admin/edit.gif" alt="Edit" title="Edit" /></button> <button name="delete" class="button" onclick="javascript:return confirm(\'' . $this->l('Are you sure you want to remove this block?') . '\');" ><img src="../img/admin/delete.gif" alt="Delete" title="Delete" /></button> </form></td>'; $tableBlock .= '</tr>'; } return $tableBlock; } public function getData() { $sql = ' SELECT * FROM `' . _DB_PREFIX_ . 'row_product`'; return (Db::getInstance()->executeS($sql)); } public function editRowProduct() { $sql = ' SELECT * FROM `' . _DB_PREFIX_ . 'row_product` WHERE id_row_product =' . $_POST['id_row_product']; $r = Db::getInstance()->executeS($sql); foreach ($r as $k => $v) { $r[0]['view'] = Db::getInstance()->executeS('SELECT * FROM ' . _DB_PREFIX_ . 'view_image WHERE id_row_product =' . $v['id_row_product']); } return $r; } public function deleteRowProduct($id) { $s = Db::getInstance()->executeS('SELECT * FROM ' . _DB_PREFIX_ . 'row_product WHERE id_row_product=' . $id); unlink($_SERVER['DOCUMENT_ROOT'] . _MODULE_DIR_ . 'prestashoptool/image/' . $s[0]['image']); $r = Db::getInstance()->executeS('SELECT * FROM ' . _DB_PREFIX_ . 'view_image WHERE id_row_product=' . $id); foreach ($r as $key => $value) { unlink($_SERVER['DOCUMENT_ROOT'] . _MODULE_DIR_ . 'prestashoptool/image/view1/' . $value['view_image1']); unlink($_SERVER['DOCUMENT_ROOT'] . _MODULE_DIR_ . 'prestashoptool/image/view2/' . $value['view_image2']); } Db::getInstance()->delete(_DB_PREFIX_ . 'row_product', 'id_row_product = ' . (int) $id); Db::getInstance()->delete(_DB_PREFIX_ . 'view_image', 'id_row_product = ' . (int) $id); }}?> Edited April 15, 2014 by NaveenYadav (see edit history) Link to comment Share on other sites More sharing options...
NaveenYadav Posted April 15, 2014 Author Share Posted April 15, 2014 Hello Vekia, In above Code you can see red section of php. here I want to add texteditor. Thanks Link to comment Share on other sites More sharing options...
vekia Posted April 15, 2014 Share Posted April 15, 2014 include require_once("../../config/config.inc.php"); library then you will be able to use any controller you want without adding it as a library Link to comment Share on other sites More sharing options...
NaveenYadav Posted April 17, 2014 Author Share Posted April 17, 2014 Hello Vekia, Thanks for reply I think you understand wrong,Please see this screen-shot. http://awesomescreenshot.com/0902o3a145 After that you have better Idea what I want. Thanks Link to comment Share on other sites More sharing options...
NaveenYadav Posted April 24, 2014 Author Share Posted April 24, 2014 Hello Vekia, Any help ? Link to comment Share on other sites More sharing options...
vekia Posted April 24, 2014 Share Posted April 24, 2014 Hello Vekia, Thanks for reply I think you understand wrong,Please see this screen-shot. http://awesomescreenshot.com/0902o3a145 After that you have better Idea what I want. Thanks use class="rte" for this <textarea> field. Link to comment Share on other sites More sharing options...
NaveenYadav Posted April 25, 2014 Author Share Posted April 25, 2014 Thanks for reply..... But Still It is not working. Have you another way to do that? Thanks Link to comment Share on other sites More sharing options...
Recommended Posts