示例#1
0
    function deleteMediFile()
    {
        // Add Language file.
        $lang = JFactory::getLanguage();
        $lang->load('com_quick2cart', JPATH_ADMINISTRATOR);
        // get Product_id via ajax url.
        $jinput = JFactory::getApplication()->input;
        $item_id = $jinput->get('pid');
        // Get file id for delete.
        $file_id = $jinput->get('file_id');
        $path = JPATH_SITE . DS . 'components' . DS . 'com_quick2cart' . DS . 'models' . DS . 'attributes.php';
        if (!class_exists('attributes')) {
            // require_once $path;
            JLoader::register('attributes', $path);
            JLoader::load('attributes');
        }
        $quick2cartModelAttributes = new quick2cartModelAttributes();
        $path = JPATH_SITE . DS . 'components' . DS . 'com_quick2cart' . DS . 'helpers' . DS . 'product.php';
        if (!class_exists('productHelper')) {
            // require_once $path;
            JLoader::register('productHelper', $path);
            JLoader::load('productHelper');
        }
        $productHelper = new productHelper();
        $delFiles = array();
        $delFiles[] = $file_id;
        $productHelper->deleteProductMediaFile($delFiles);
        $attributes = $quick2cartModelAttributes->getItemAttributes($item_id);
        $getMediaDetail = $productHelper->getMediaDetail($item_id);
        if (empty($getMediaDetail)) {
            $html = '<thead>
						<tr>
							<th width="35%" align="left"><b>' . JText::_('QTC_MEDIAFILE_NAME') . '</b></th>
							<th width="30%"	align="left"><b>' . JText::_('QTC_MEDIAFILE_PURCHASE_REQUIRE') . '</b> </th>
							<th width="15%"	align="left"></th>
						</tr>
					</thead>';
            $html .= '<tr class="empty_media">
					<td colspan="3">' . JText::_('QTC_MEDIAFILE_EMPTY_MSG') . '</td>
				</tr>';
            $data['html'] = $html;
            echo json_encode($html);
        }
        jexit();
    }
示例#2
0
 /**
  * This function save product media details
  * @param $media_detail array  - Media detail
  * */
 function saveProdMediaDetails($media_detail, $item_id, $deleteOldRec = 1)
 {
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     $db = JFactory::getDBO();
     //   get privious  file ids
     $query = 'SELECT  `file_id` FROM `#__kart_itemfiles` where `item_id`=' . $item_id;
     $db->setQuery($query);
     $oldMedia = $db->loadColumn();
     $comquick2cartHelper = new comquick2cartHelper();
     $params = JComponentHelper::getParams('com_quick2cart');
     $destinationPath = $params->get('eProdUploadDir', 'media/com_quick2cart/productfiles');
     $eProdExpFormat = $params->get('eProdExpFormat', 'epMonthExp');
     $eProdUExpiryMode = $params->get('eProdUExpiryMode', 'epMaxDownload');
     //  down count/ date limit / both
     foreach ($media_detail as $media) {
         if (empty($media['mediaFilePath'])) {
             continue;
         }
         $file = new stdClass();
         $file->file_id = $media['file_id'];
         $file->file_display_name = $media['name'];
         $file->item_id = $item_id;
         $file->state = isset($media['status']) ? true : false;
         $file->purchase_required = isset($media['purchaseReq']) ? true : false;
         // @TODO : if date expiry mode, keep this value as default according to config
         $file->download_limit = !empty($media['downCount']) ? $media['downCount'] : -1;
         $file->expiry_mode = $eProdExpFormat == 'epMonthExp' ? 1 : 0;
         // @TODO : if download limit mode, keep this value as default according to config
         $file->expiry_in = !empty($media['expirary']) ? $media['expirary'] : 2;
         /*elseif ($eProdUExpiryMode == "epDateExpiry")
         		{
         		//  use data expiration ( not download count )
         		//  null - field not considered, -1 - unlimited , other for req count
         		// 	$file->download_limit = -1;  //  for edit and changed config  ( NULL DOESN'T INSERT IN DB BZ DATATYPE MISMATCH)
         		//  IN DAY  OR MONTHS
         		$file->expiry_mode = ($eProdExpFormat == 'epMonthExp') ? 1:0;
         		$file->expiry_in = $media['expirary'];
         		}
         		elseif ($eProdUExpiryMode == "epMaxDownload")
         		{
         		$file->download_limit = $media['downCount'];
         		// $file->expiry_mode = -1; //  -1 for dont consider field
         		// $file->expiry_in = 0;
         		}*/
         if (empty($media['file_id'])) {
             $file->cdate = date('Y-m-d');
         } else {
             //  if media editing then
             $medKey = array_search($media['file_id'], $oldMedia);
             if (isset($medKey)) {
                 //  present data (not deleted media file)
                 unset($oldMedia[$medKey]);
             }
         }
         $file->mdate = date('Y-m-d H:i:s');
         //  for new file, check for file save path
         if (empty($media['file_id']) && !empty($media['mediaFilePath'])) {
             //  get temparary uploaded path
             $tempSource = JPATH_SITE . '/tmp/' . $media['mediaFilePath'];
             $uploadedFile = explode(DS, $tempSource);
             $filNameIndex = count($uploadedFile) - 1;
             $fileName = $uploadedFile[$filNameIndex];
             //  new destination path
             $newDestination = JPATH_ROOT . DS . $destinationPath;
             //  if folder path not exist
             if (!JFolder::exists($newDestination)) {
                 $status = JFolder::create($newDestination);
             }
             //  move a file from temporary location to newlocation
             $newDestination = $newDestination . DS . $fileName;
             $uploadSuccess = JFile::move($tempSource, $newDestination);
         }
         $file->filePath = $media['mediaFilePath'];
         $action = empty($media['file_id']) ? 'insertObject' : 'updateObject';
         if (!$db->{$action}('#__kart_itemfiles', $file, 'file_id')) {
             echo $db->stderr();
             return 0;
         }
     }
     $productHelper = new productHelper();
     if ($deleteOldRec == 1) {
         $productHelper->deleteProductMediaFile($oldMedia);
     }
     return 1;
 }