function editProduct(&$a) { global $mainframe; $document =& JFactory::getDocument(); $document->addScript(JURI::root(true) . '/administrator/components/com_caddy/js/caddy.js'); display::header(); $cid = JRequest::getVar('cid', array(0), '', 'array'); $edit = $cid != array(0); $text = $edit ? JText::_('Edit') : JText::_('New'); JToolBarHelper::title(JText::_("SimpleCaddy {$text}"), 'generic.png'); JToolBarHelper::save('save', 'Save'); JToolBarHelper::apply(); if ($edit) { // for existing items the button is renamed `close` JToolBarHelper::cancel('cancel', 'Close'); } else { JToolBarHelper::cancel(); } $cfg = new sc_configuration(); $currency = $cfg->get("currency"); $tsep = $cfg->get("thousand_sep"); $decsep = $cfg->get("decimal_sep"); $decs = $cfg->get("decimals"); $scats = $cfg->get("prodcats"); $curalign = $cfg->get("curralign"); $cats = explode("\r\n", $scats); $optiongroups = new optiongroups(); $lstoptgroups = $optiongroups->getgroups($a->prodcode); ?> <form method="post" name="adminForm" action="index2.php"> <table class="adminform" width="100%"><tr><th><?php echo ($a->id ? JText::_('SC_EDIT') : JText::_('SC_NEW')) . " " . JText::_('SC_PRODUCT'); ?> </th><th> </th></tr> <tr> <td width="185"><?php echo JText::_('SC_PRODUCT_CODE'); ?> </td> <td><input type="text" name="prodcode" value="<?php echo $a->prodcode; ?> " maxlength="13"/><?php echo JText::_('SC_MAX_10_CHAR'); ?> </td> </tr> <tr> <td><?php echo JText::_('SC_PRODUCT_NAME'); ?> </td> <td><input type="text" name="shorttext" value="<?php echo $a->shorttext; ?> "/></td> </tr> <tr> <td><?php echo JText::_('SC_PRODUCT_CATEGORY'); ?> </td> <td> <select name="category"> <?php foreach ($cats as $cat) { echo "<option value='{$cat}' " . ($cat == $a->category ? ' selected' : '') . ">{$cat}</option>"; } ?> </select> </td> </tr> <tr> <td><?php echo JText::_('SC_AVAILABLE_QTY'); ?> </td> <td> <input type="text" name="av_qty" value="<?php echo $a->av_qty; ?> " size="10"/> </td> </tr> <tr> <td><?php echo JText::_('SC_PRICE_PER_UNIT'); ?> </td> <td> <?php if ($curalign == 1) { echo $currency; } ?> <input size="10" type="text" name="unitprice" value="<?php echo $a->unitprice; ?> "/> <?php if ($curalign == 0) { echo $currency; } echo JText::_('Do not format your price'); ?> </td> </tr> <tr> <td><?php echo JText::_('SC_SHIPPING_POINTS'); ?> </td> <td> <input type="text" name="shippoints" value="<?php echo $a->shippoints; ?> " size="5"/> </td> </tr> <tr><td><?php echo JText::_('SC_PUBLISHED'); ?> </td> <td> <?php $show_hide = array(JHTML::_('select.option', 0, JText::_('No')), JHTML::_('select.option', 1, JText::_('Yes'))); foreach ($show_hide as $value) { echo "<input type='radio' value='{$value->value}' name='published' " . ($a->published == $value->value ? ' checked' : '') . ">{$value->text}"; } ?> </td> </tr> </table> <?php // check if the product exists before adding options if ($a->id) { ?> <table class="adminform" border="1"><tr><th><?php echo JText::_('SC_OPTIONS'); ?> <input type="button" name="addbtn" onclick="submitbutton('addoptgroup')" value="<?php echo JText::_('Add Option'); ?> " /></th><th width="270"><?php echo JText::_('SC_SHOW_AS'); ?> </th><th width="60"><?php echo JText::_('SC_ORDER'); ?> </th><th width="120"><?php echo stripslashes(JText::_('SC_IND_OPTIONS')); ?> </th><th> </th></tr> <?php $showas = new optionsshowas(); foreach ($lstoptgroups as $optgroup) { echo "\n<tr>"; echo "<td><a class='modal' href='index2.php?option=com_caddy&action=optiongroups&task=show&optgrid={$optgroup->id}&productid={$a->id}&tmpl=component'>{$optgroup->title}</a></td>"; echo "<td>"; echo $showas->type[$optgroup->showas]; echo "</td>"; echo "<td>{$optgroup->disporder}</td>"; if ($optgroup->showas != 5 and $optgroup->showas != 6) { // exclude the ones without options echo "<td><a class='modal' href='index2.php?option=com_caddy&action=options&task=showindoptions&optgrid={$optgroup->id}&tmpl=component&productid={$a->id}'>" . JText::_('SC_IND_OPTIONS') . "</a></td>"; } else { // no options? just display an empty cell for table alignment echo "<td> </td>"; } echo "<td><a class='button' href='index.php?option=com_caddy&action=optiongroups&task=remove&optgrid={$optgroup->id}&productid={$a->id}'>" . JText::_('Remove option') . "</td>"; echo "</tr>"; } ?> </table> <?php } else { echo JText::_("SC_SAVE_FIRST"); } ?> <input type="hidden" name="id" value="<?php echo $a->id; ?> " /> <input type="hidden" name="option" value="com_caddy" /> <input type="hidden" name="action" value="products" /> <input type="hidden" name="task" value="" /> <input type="hidden" name="boxchecked" value="0" /> <input type="hidden" name="hidemainmenu" value="0" /> </form> <?php }
function getSCSingle($params, $pluginParams, $debugmode = 0) { global $Itemid, $mainframe; $dis = new dis(); // printf("<pre>%s</pre>", print_r($pluginParams,1)); $classsuffix = isset($params['classsfx']) ? $params['classsfx'] : ""; $prodcode = $params['code']; $defaultqty = isset($params['defqty']) ? $params['defqty'] : 1; // default qty set in qty edit box $minqty = isset($params['minqty']) ? $params['minqty'] : 0; $strqties = isset($params['qties']) ? $params['qties'] : null; $checkoos = isset($params['checkoos']) ? $params['checkoos'] : 0; $picname = isset($params['picname']) ? $params['picname'] : ""; $aqties = explode(",", $strqties); $db =& JFactory::getDBO(); $query = "SELECT * FROM #__sc_products WHERE prodcode='{$prodcode}'"; $db->setQuery($query); $product = $db->loadObject(); if (!$product) { $html = "<div class='sccart{$classsuffix}'>"; $str = JText::sprintf("SC_PRODUCT_NOT_FOUND", $prodcode); $html .= $str; $html .= "</div>"; return $html; } if ($product->published == '0') { $html = "<div class='sccart{$classsuffix}'>"; $str = JText::sprintf("SC_PRODUCT_NOT_PUBLISHED", $prodcode); $html .= $str; $html .= "</div>"; return $html; } if (!$db->query()) { echo "<script> alert('" . $db->getErrorMsg() . "'); window.history.go(-1); </script>\n"; exit; } $prodpresentation = ""; if ($pluginParams->get('showproductcodetext')) { $prodpresentation .= "\n<div class='scproduct{$classsuffix}'>#PRODUCTCODETEXT# {$dis->separator}</div>"; } if ($pluginParams->get('showproductcode')) { $prodpresentation .= "\n<div class='scprodcode{$classsuffix}'>#PRODUCTCODE# {$dis->separator}</div>"; } if ($pluginParams->get('showtitle')) { $prodpresentation .= "\n<div class='scshorttext{$classsuffix}'>#SHORTTEXT# {$dis->separator}</div>"; } if ($pluginParams->get('showunitpricetext')) { $prodpresentation .= "\n<div class='scunitpricetext{$classsuffix}'>#UNITPRICETEXT# {$dis->separator}</div>"; } if ($pluginParams->get('showunitprice')) { $prodpresentation .= "\n<div class='scunitprice{$classsuffix}'>#UNITPRICE# {$dis->separator}</div>"; } if ($pluginParams->get('showquantitytext')) { $prodpresentation .= "\n<div class='scqtytext{$classsuffix}'>#QUANTITYTEXT# {$dis->separator}</div>"; } $prodpresentation .= "\n<div class='scqty{$classsuffix}'>#QUANTITY# {$dis->separator}</div>"; $prodpresentation .= "\n#CARTOPTIONS#"; $prodpresentation .= "\n<div class='atczone{$classsuffix}'>#ADDTOCARTBUTTON#</div>"; $html = "\n<div class='sccart{$classsuffix}'>"; $html .= "\n<form name='addtocart{$product->id}' action='index.php' method='post'>"; $amount = number_format($product->unitprice, $dis->decs, $dis->dsep, $dis->tsep); if ($dis->curralign == 1) { $amount = $dis->currency . " " . $amount; } else { $amount = $amount . " " . $dis->currency; } $html .= $prodpresentation; $productoptions = new productoption(); $optionhtml = "<div class='cartoptions{$classsuffix}'>"; if ($pluginParams->get('showcartoptionstitle')) { $optionhtml .= "\n<div class='cartoptionstitle{$classsuffix}'>#CARTOPTIONSTITLE#</div>"; } $hasoptions = 0; $optgroups = new optiongroups(); $optiongroups = $optgroups->getgroups($product->prodcode); if (count($optiongroups)) { foreach ($optiongroups as $optiongroup) { $groupid = $optiongroup->id; $options = new productoption(); $lstoptions = $options->getbygroup($groupid); $show = "optionshow" . $optiongroup->showas; if ($pluginParams->get('showcartoptionstitle')) { $optionhtml .= "\n<div class='cartoptionstitle{$classsuffix}'>{$optiongroup->title}</div>"; } $optionhtml .= $dis->{$show}($lstoptions, $product, $groupid, $classsuffix, $picname); } } else { // product without options - generate id from productcode $id = md5($product->prodcode . $picname); $optionhtml .= "\n<input type='hidden' value='{$id}' name='edtoption' />"; } $optionhtml .= "</div>"; if ($checkoos == 1) { // check for minimum quantitites/ out of stock if ($product->av_qty >= 1) { // product still available $atcbtn = "\n<input type='submit' name='submit' value='" . JText::_('SC_ADD_TO_CART') . "' class='scp_atc{$classsuffix}' />"; } else { // product quantity is 0 $atcbtn = "\n<input type='submit' name='submit' value='" . JText::_('SC_OUT_OF_STOCK') . "' class='scp_atc{$classsuffix}' disabled='disabled' />"; } } else { $atcbtn = "\n<input type='submit' name='submit' value='" . JText::_('SC_ADD_TO_CART') . "' class='scp_atc{$classsuffix}' />"; } $qtyfield = "\n<input type='" . ($pluginParams->get('showquantity') ? 'text' : 'hidden') . "' name='edtqty' value='{$defaultqty}' class='scp_qty{$classsuffix}' />"; if ($strqties) { // specific quantities given $qtyfield = "<select name='edtqty' class='scp_selectqty{$classsuffix}'>"; foreach ($aqties as $key => $value) { $qtyfield .= "<option value='{$value}'>{$value}</option>"; } $qtyfield .= "</select>"; } $html .= "\n<input type='hidden' name='edtprodcode' value='{$product->prodcode}' />"; $html .= "\n<input type='hidden' name='edtshorttext' value='{$product->shorttext}' />"; $html .= "\n<input type='hidden' name='edtunitprice' value='{$product->unitprice}' />"; $html .= "\n<input type='hidden' name='option' value='com_caddy' />"; $html .= "\n<input type='hidden' name='action' value='addtocart' />"; $html .= "\n<input type='hidden' name='picname' value='{$picname}' />"; $html .= "\n<input type='hidden' name='Itemid' value='{$Itemid}' />"; if ($minqty > 0) { // check for minimum quantity in the component $html .= "\n<input type='hidden' name='minqty' value='{$minqty}' />"; } if ($pluginParams->get('stayonpage') == 1) { $html .= "\n<input type='hidden' name='lasturl' value='" . urlencode($_SERVER['REQUEST_URI']) . "' />"; $html .= "\n<input type='hidden' name='stayonpage' value='1' />"; } $html .= "\n</form>"; $html .= "</div>"; //now replace any variables $html = str_replace("#PRODUCTCODETEXT#", JText::_('SC_PRODUCT'), $html); $html = str_replace("#PRODUCTCODE#", $product->prodcode, $html); $html = str_replace("#SHORTTEXT#", stripslashes($product->shorttext), $html); $html = str_replace("#UNITPRICETEXT#", JText::_('SC_PRICE_PER_UNIT'), $html); $html = str_replace("#UNITPRICE#", $amount, $html); $html = str_replace("#QUANTITY#", $qtyfield, $html); $html = str_replace("#QUANTITYTEXT#", JText::_('SC_QUANTITY'), $html); $html = str_replace("#ADDTOCARTBUTTON#", $atcbtn, $html); $html = str_replace("#CARTOPTIONS#", $optionhtml, $html); if (trim($product->options)) { $html = str_replace("#CARTOPTIONSTITLE#", JText::_('SC_OPTIONS'), $html); } else { $html = str_replace("#CARTOPTIONSTITLE#", "", $html); } return $html; }