<div id="firmTours"> <?php if ($this->beginCache("firmDescriptionTours-" . $item->id . "_" . Yii::app()->getLanguage(), array('duration' => SiteHelper::getConfig("firmDescriptionTours")))) { ?> <div class="row"> <?php // Категории $listCategory = CatalogToursCategory::sql("SELECT id, owner FROM `catalog_tours_category` WHERE owner>0 AND id IN( SELECT category_id FROM catalog_tours WHERE firm_id=" . $item->id . " AND del=0 AND active=1 )"); $reCategory = array(); $reCategory2 = array(); // Раскладываем по OWNER-у foreach ($listCategory as $category) { $reCategory[$category["owner"]][] = $category["id"]; } // Подменяем ID на обект и подсчитываем количество foreach ($reCategory as $category => $value) { $ownerCategoryModel = CatalogToursCategory::fetch($category); $array = array(); foreach ($value as $cid) { if ($cid > 0) { $obj = CatalogToursCategory::fetch($cid); $array[] = $obj; } } $reCategory2[$ownerCategoryModel->name] = $array; } // Странны $listCountry = CatalogCountry::sql("SELECT id FROM `catalog_country` WHERE id IN( SELECT country_id FROM catalog_tours WHERE firm_id=" . $item->id . " AND del=0 AND active=1 )"); $reCountry2 = array(); // Подменяем ID на обект и подсчитываем количество foreach ($listCountry as $id => $keys) {
public function run($args) { $countLimit = SiteHelper::getConfig("subscribee_count_send"); $emails = array(); $countSend = 0; $res = SubscribeItems::findByAttributes(array("status_id" => 2)); foreach ($res as $line) { // 1 - отправляем и зарегеным и подписчикам if ($line->users == 1 || $line->users == 2) { $lisUsers = CatalogUsers::sql("SELECT u.* FROM catalog_users u WHERE `active`=1 AND subscribe=1 AND !exists( SELECT id FROM subscribe_send WHERE email=u.email AND item_id='" . $line->id . "' AND is_reg=1 ) LIMIT " . $countLimit); foreach ($lisUsers as $userLine) { $emails[] = array("email" => $userLine["email"], "name" => $userLine["name"]); $newSend = new SubscribeSend(); $newSend->item_id = $line->id; $newSend->user_id = $userLine["id"]; $newSend->email = $userLine["email"]; $newSend->is_reg = 1; if (!$newSend->save()) { print_r($newSend->getErrors()); } } } if (sizeof($emails) < $countLimit && ($line->users == 1 || $line->users == 3)) { $lisUsers = CatalogUsers::sql("SELECT u.* FROM subscribe_users u WHERE !exists( SELECT id FROM subscribe_send WHERE email=u.email AND item_id='" . $line->id . "' AND is_reg=0 ) LIMIT " . ($countLimit - sizeof($emails))); foreach ($lisUsers as $userLine) { $emails[] = array("email" => $userLine["email"], "name" => $userLine["name"]); $newSend = new SubscribeSend(); $newSend->item_id = $line->id; $newSend->user_id = null; $newSend->email = $userLine["email"]; $newSend->is_reg = 0; if (!$newSend->save()) { print_r($newSend->getErrors()); } } } if ($line->users == 4) { $usersList = trim(strip_tags($line->users_list)); if (!empty($usersList)) { $listEmail = explode(",", $usersList); for ($m = 0; $m < sizeof($listEmail); $m++) { $listEmail[$m] = trim($listEmail[$m]); $ext = SubscribeSend::findByAttributes(array("item_id" => $line->id, "email" => $listEmail[$m])); if (sizeof($ext) == 0) { $emails[] = array("email" => $listEmail[$m], "name" => "пользователь"); $newSend = new SubscribeSend(); $newSend->item_id = $line->id; $newSend->user_id = null; $newSend->email = $listEmail[$m]; $newSend->is_reg = 0; if (!$newSend->save()) { print_r($newSend->getErrors()); } } } } } if (sizeof($emails) > 0) { for ($n = 0; $n < sizeof($emails); $n++) { $countSend++; $message = $line->description; $message = str_replace("@user_name@", $emails[$n]["name"], $message); SiteHelper::mailto($line->subject, $line->from, $emails[$n]["email"], stripslashes($message), "", "", array("<!-- @openSubscribeLink@ -->" => "<img src=\"" . Yii::app()->params["baseUrl"] . "site/subscribeOpen/subscribe/" . $line->id . "/email/" . $emails[$n]["email"] . "\" alt=\"\" style=\"width:0px;height:0px\" />")); } } // Сохраняем количество оптравленных, чтобы не считать каждый раз if ($countSend > 0) { $line->count_send += $countSend; $line->save(); } // Если адресатов нет или их количество меньше чем лимит то финализируем рассылку if (sizeof($emails) == 0 || $countSend < $countLimit) { $line->status_id = 3; $line->save(); } } }
private function optimization($fileUrl, $img_type = "", $upload_type, $dopUrl = "", $catalog = "") { $fileName = basename($fileUrl); $dirPath = $dopUrl . dirname($fileUrl) . "/"; $typeData = Yii::app()->params["images"][$img_type]; list($width0, $height0) = getimagesize($dopUrl . $fileUrl); $wprocent = ceil($height0 * 100 / $width0); $hprocent = ceil($width0 * 100 / $height0); $i = 0; $cout = ""; for ($i = 1; $i <= sizeof($typeData); $i++) { $width = $typeData[$i]['width']; $height = $typeData[$i]['height']; if ($width > 0 || $height > 0) { if ($i == 1) { $new_file_name = $dirPath . $fileName; if (!$width && !$height) { list($width, $height) = getimagesize($dopUrl . $fileUrl); } } else { $new_file_name = $dirPath . $i . "_" . $fileName; if ($width0 == $height) { if (!$width && $height) { $width = $height; } if ($width && !$height) { $height = $width; } } } // Если указынны оба параметра то высоту обнуляем меньший из параметров if ($width > 0 && $height > 0) { if ($width >= $height) { $height = 0; } if ($width < $height) { $width = 0; } } // Если не указан один из параметров, то недостоющий расщитываем if (!$width && $height) { $width = ceil($height * $hprocent / 100); } if ($width && !$height) { $height = ceil($width * $wprocent / 100); } // Проверяем чтобы указынне параметры небыли больше чем заданы для данного типа картинки if ($width > $width0) { $width = $width0; } if ($height > $height0) { $height = $height0; } if ($width && $height) { switch ($upload_type) { case "jpg": $image_o = imagecreatefromjpeg($dopUrl . $fileUrl); break; case "image/jpg": $image_o = imagecreatefromjpeg($dopUrl . $fileUrl); break; case "jpeg": $image_o = imagecreatefromjpeg($dopUrl . $fileUrl); break; case "image/jpeg": $image_o = imagecreatefromjpeg($dopUrl . $fileUrl); break; case "image/pjpeg": $image_o = imagecreatefromjpeg($dopUrl . $fileUrl); break; case "gif": $image_o = imagecreatefromgif($dopUrl . $fileUrl); break; case "image/gif": $image_o = imagecreatefromgif($dopUrl . $fileUrl); break; case "png": $image_o = imagecreatefrompng($dopUrl . $fileUrl); break; case "image/png": $image_o = imagecreatefrompng($dopUrl . $fileUrl); break; } list($width_o, $height_o) = getimagesize($dopUrl . $fileUrl); $new_file = imagecreatetruecolor($width, $height); $res = imagecopyresampled($new_file, $image_o, 0, 0, 0, 0, $width, $height, $width_o, $height_o); if ($res === True) { switch ($upload_type) { case "jpeg": ImageJPEG($new_file, $new_file_name, Yii::app()->params["images_quality"]); break; case "image/jpeg": ImageJPEG($new_file, $new_file_name, Yii::app()->params["images_quality"]); break; case "image/pjpeg": ImageJPEG($new_file, $new_file_name, Yii::app()->params["images_quality"]); break; case "jpg": ImageJPEG($new_file, $new_file_name, Yii::app()->params["images_quality"]); break; case "image/jpg": ImageJPEG($new_file, $new_file_name, Yii::app()->params["images_quality"]); break; case "gif": ImageGIF($new_file, $new_file_name); break; case "image/gif": ImageGIF($new_file, $new_file_name); break; case "png": ImagePNG($new_file, $new_file_name); break; case "image/png": ImagePNG($new_file, $new_file_name); break; } } else { $cout = "<p class=\"err\">Произошла ошибка обработки файла (" . $new_file_name . ")</p>"; } #Наложение логотипа на картинки if (SiteHelper::getConfig("watermark")) { $this->addLogoOnImage($dopUrl . $fileUrl, $upload_type, $dopUrl . SiteHelper::getConfig("watermark"), $catalog); } } } } return $cout; }
public function actionSetPublish() { $id = (int) Yii::app()->request->getParam("id", 0); $catalog = Yii::app()->request->getParam("catalog"); if ($id > 0 && !empty($catalog)) { $newCatalog = new $catalog(); $modelClass = SiteHelper::getCamelCase($newCatalog->tableName()); $model = $modelClass::fetch($id); $listImages = CatGallery::findByAttributes(array("catalog" => $newCatalog->tableName(), "item_id" => $id)); $imagesMin = SiteHelper::getConfig("publish_min_images"); $sizeofImages = sizeof($listImages); if ($model->image) { $sizeofImages++; } // Для CatalogFirmsBannersAdd не должно влиять ограичение перед публиацией по количесву картинок if ($sizeofImages >= $imagesMin || $catalog == "CatalogFirmsBannersAdd" || $catalog == "CatalogFirmsBanners") { $error = false; $commentModel = $catalog::fetch($id); if (($catalog == "CatalogFirmsBannersAdd" || $catalog == "CatalogFirmsBanners") && !$commentModel->file) { $error = true; } if ($commentModel->user_id->id != Yii::app()->user->getId() && $commentModel->firm_id->user_id->id != Yii::app()->user->getId()) { $error = true; } if (!$error) { if ($commentModel->user_id && $commentModel->user_id->id > 0) { $id = $commentModel->user_id->id; } else { $id = $commentModel->firm_id->user_id->id; } if ($commentModel->id > 0 && $id == Yii::app()->user->getId()) { if ($commentModel->active == 0) { $commentModel->active = 1; $action = "publish"; } else { $commentModel->active = 0; $action = "nopublish"; } SiteHelper::setLog($newCatalog->tableName(), $action, $commentModel->user_id->id, Yii::app()->user->getId()); if ($commentModel->save()) { echo 1; } else { print_r($commentModel->getErrors()); } return; } } } else { echo 3; return; } } echo 0; return; }
public function actionDescription($gallError = "") { $_POST["CatalogFirmsBannersAdd"]["firm_id"] = $this->firmId; $_POST["CatalogFirmsBannersAdd"]["user_id"] = Yii::app()->user->getId(); if (!Yii::app()->user->isGuest) { Yii::app()->page->title = Yii::t("page", "Описание"); $id = (int) Yii::app()->request->getParam("id", 0); $status = Yii::app()->request->getParam("status", ""); $error = Yii::app()->request->getParam("error", ""); $addClass = $this->addModel; if (!empty($id)) { $item = $addClass::fetch($id); } else { $item = new $addClass(); SiteHelper::setLog($item->tableName(), "open_add_form", $item->id, Yii::app()->user->getId()); } $count = CatalogBannerRequest::count(); $maxCount = SiteHelper::getConfig("banner_max_count"); $checkedRequest = CatalogBannerRequest::findByAttributes(array("banner_id" => $item->id)); if (!$item->id || ($item->user_id && $item->user_id->id == Yii::app()->user->getId() || $item->firm_id && $item->firm_id->user_id->id == Yii::app()->user->getId())) { if (property_exists($item, "firm_id") && $item->firm_id) { $firm = $item->firm_id; } if (!property_exists($item, "firm_id") && $item->id) { $firm = $item; } if (empty($firm) || $firm->id == 0) { $fid = (int) Yii::app()->request->getParam("fid", 0); $firm = CatalogFirms::fetch($fid); } $message = !empty($status) && $status == 'saved' ? Yii::t("user", "Сохранено") : ""; // Описание объявления if (!empty($_POST["update"])) { if (!$item->id) { $isAdd = true; } else { $isAdd = false; } $item->setAttributesFromArray($_POST[$addClass]); //$item->is_resume = 0; if (!$item->date) { $item->date = time(); } $item->user_id = Yii::app()->user->getId(); if ($item->save()) { if ($isAdd) { $action = "create"; } else { $action = "edit"; } SiteHelper::setLog($item->tableName(), $action, $item->id, Yii::app()->user->getId()); if (!empty($_POST["banner_request"])) { if ($count < $maxCount) { if (sizeof($checkedRequest) == 0) { $newRequest = new CatalogBannerRequest(); $newRequest->banner_id = $item->id; $newRequest->date = time(); $newRequest->active = 0; $newRequest->save(); $newRequest->onBannerRequest(new CModelEvent($newRequest), array("id" => $newRequest->id, "date" => date("d.m.Y"))); } } } $this->redirect(SiteHelper::createUrl("/user/" . Yii::app()->controller->getId() . "/description/", array("id" => $item->id, "fid" => $firm->id, "status" => "saved"))); die; } } $this->render("description", array("checkedRequest" => sizeof($checkedRequest), "count" => $count, "maxCount" => $maxCount, "item" => $item, "firm" => $firm, "listGallery" => array(), "message" => $message, "addImage" => null, "comMessage" => "", "gallMessage" => "", "listComments" => array())); } } }