Exemple #1
0
 /**
  * Save videos to youtube.
  * @param Advertisement $model
  * @param CUploadedFile[] $videos
  */
 public static function processAdvertisement($model, $videos)
 {
     if (!empty($videos) && is_array($videos)) {
         $result = array();
         foreach ($videos as $video) {
             $result[] = Upload($video, $model->name, $model->description, 'Animals', 'Tags');
         }
         if (!empty($result)) {
             $model->youtube = $result;
             $model->save();
         }
     }
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $this->addToolbar();
     $model = new Advertisement();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Advertisement'])) {
         $model->attributes = $_POST['Advertisement'];
         //$model->link = Yii::app()->format->formatUrl($model->link);
         if ($model->save()) {
             $this->redirect(array('index'));
         }
     }
     $this->render('form', array('model' => $model));
 }
 function initializeModule($request_method, $request_data)
 {
     global $error_msg;
     $error = false;
     $msg = array();
     $form_data = NULL;
     $edit = false;
     $message = NULL;
     // check permissions!
     $user_may = false;
     $user_may = PermissionsHandler::can_user(PA::$login_uid, array('permissions' => 'manage_ads'));
     // check for manageads of group permissions
     if (!empty($_REQUEST['gid']) && !$user_may) {
         // we do this checl only if the user is not already permitted to manage ads
         $gp_access = PermissionsHandler::can_group_user(PA::$login_uid, $_REQUEST['gid'], array('permissions' => 'manage_ads'));
         $user_may = $gp_access;
     }
     if (!$user_may) {
         $error_msg = __("You do not have permission to manage Ads.");
         return "skip";
     }
     // paging
     if (!empty($request_data['page'])) {
         $this->Paging["page"] = (int) $request_data['page'];
     }
     if (!empty($request_data['action']) && $request_data['action'] == 'edit' && !empty($request_data['ad_id'])) {
         $edit = TRUE;
         $res = Advertisement::get($params = NULL, $condition = array('ad_id' => (int) $request_data['ad_id']));
         if (!empty($res)) {
             $form_data['ad_id'] = $res[0]->ad_id;
             $form_data['ad_image'] = $res[0]->ad_image;
             $form_data['ad_script'] = $res[0]->ad_script;
             $form_data['ad_url'] = $res[0]->url;
             $form_data['ad_title'] = $res[0]->title;
             $form_data['ad_description'] = $res[0]->description;
             $form_data['ad_page_id'] = $res[0]->page_id;
             $form_data['orientation'] = $res[0]->orientation;
             $form_data['created'] = $res[0]->created;
         }
     } else {
         if (!empty($request_data['action']) && $request_data['action'] == 'delete' && !empty($request_data['ad_id'])) {
             if (!empty($request_data['ad_id'])) {
                 try {
                     Advertisement::delete((int) $request_data['ad_id']);
                     $error_msg = 19013;
                 } catch (CNException $e) {
                     $msg[] = $e->message;
                 }
             }
         } else {
             if (!empty($request_data['action']) && !empty($request_data['ad_id'])) {
                 $update = false;
                 switch ($request_data['action']) {
                     case 'disable':
                         $field_value = DELETED;
                         $msg_id = 19010;
                         $update = true;
                         break;
                     case 'enable':
                         $field_value = ACTIVE;
                         $msg_id = 19011;
                         $update = true;
                         break;
                 }
                 if ($update) {
                     $update_fields = array('is_active' => $field_value);
                     $condition = array('ad_id' => $request_data['ad_id']);
                     try {
                         Advertisement::update($update_fields, $condition);
                         $error_msg = $msg_id;
                     } catch (CNException $e) {
                         $msg[] = $e->message;
                     }
                 }
             }
         }
     }
     $advertisement = new Advertisement();
     if (!$error && $request_method == 'POST' && $request_data['btn_apply_name']) {
         // if page is submitted
         if (!empty($request_data['ad_id'])) {
             $advertisement->ad_id = $request_data['ad_id'];
             $advertisement->created = $request_data['created'];
             $msg_id = 19007;
         } else {
             $msg_id = 19008;
             $advertisement->created = time();
         }
         if (!empty($_FILES['ad_image']['name'])) {
             $filename = $_FILES['ad_image']['name'];
             $uploadfile = PA::$upload_path . basename($filename);
             $myUploadobj = new FileUploader();
             $file = $myUploadobj->upload_file(PA::$upload_path, 'ad_image', TRUE, TRUE, 'image');
             $advertisement->ad_image = $form_data['ad_image'] = $file;
             if ($file == FALSE) {
                 $error = TRUE;
                 $msg[] = $myUploadobj->error;
             }
         } else {
             if (!empty($request_data['ad_id'])) {
                 $advertisement->ad_image = $request_data['edit_image'];
             }
         }
         if (empty($request_data['ad_url']) && empty($request_data['ad_script'])) {
             $error = TRUE;
             $msg[] = MessagesHandler::get_message(19012);
         }
         if (!empty($request_data['ad_url'])) {
             // if url is given then validate
             $request_data['ad_url'] = Validation::validate_url($request_data['ad_url']);
             if (!Validation::isValidURL($request_data['ad_url'])) {
                 $error = TRUE;
                 $msg[] = MessagesHandler::get_message(19009);
             }
         }
         $advertisement->user_id = PA::$login_uid;
         $advertisement->url = $form_data['ad_url'] = $request_data['ad_url'];
         $advertisement->ad_script = $form_data['ad_script'] = $request_data['ad_script'];
         $advertisement->title = $form_data['ad_title'] = $request_data['ad_title'];
         $advertisement->description = $form_data['ad_description'] = $request_data['ad_description'];
         $advertisement->page_id = $form_data['ad_page_id'] = $request_data['ad_page_id'];
         $advertisement->orientation = $form_data['orientation'] = $request_data['x_loc'] . ',' . $request_data['y_loc'];
         $advertisement->changed = time();
         $advertisement->is_active = ACTIVE;
         if (!empty($_REQUEST['gid'])) {
             $advertisement->group_id = (int) $_REQUEST['gid'];
         }
         if (!$error) {
             try {
                 $ad_id = $advertisement->save();
                 if (!empty($file)) {
                     Storage::link($file, array("role" => "ad", "ad" => $ad_id));
                 }
                 $error_msg = $msg_id;
             } catch (CNException $e) {
                 $error_msg = $e->message;
             }
         } else {
             $error_msg = implode("<br/>", $msg);
         }
     }
     $this->form_data = $form_data;
     $this->edit = $edit;
     $this->message = $message;
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Advertisement();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Advertisement'])) {
         $model->attributes = $_POST['Advertisement'];
         $model->start = strtotime($model->start);
         $model->end = strtotime($model->end);
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         } else {
             UtilHelper::writeToFile(CHtml::errorSummary($model), './public/test2.txt');
         }
     }
     $this->render('create', array('model' => $model));
 }
    $advertisement->page_id = $form_data['page_id'] = $_POST['page_id'];
    $advertisement->orientation = $form_data['orientation'] = $_POST['x_loc'] . ',' . $_POST['y_loc'];
    $ad_data = Advertisement::get(NULL, array('orientation' => $advertisement->orientation, 'is_active' => TRUE));
    if (!empty($ad_data) && !empty($advertisement->ad_id) && $advertisement->orientation != '0,0') {
        $ad_data = $ad_data[0];
        if ($advertisement->ad_id != $ad_data->ad_id) {
            $error = TRUE;
            $message = ucfirst($ad_data->type) . __(' is already enabled at specified orientation');
        }
    }
    $advertisement->changed = time();
    $advertisement->is_active = ACTIVE;
    $advertisement->type = 'textpad';
    if (!$error) {
        try {
            $advertisement->save();
            $form_data = array();
            header("Location: " . PA::$url . '/' . FILE_MANAGE_TEXTPADS . "?msg_id={$msg_id}");
            exit;
        } catch (PAException $e) {
            $msg[] = $e->message;
        }
    }
}
$page = new PageRenderer("setup_module", PAGE_MANAGE_TEXTPADS, __("Manage Textpads"), 'container_two_column.tpl', 'header.tpl', PRI, HOMEPAGE, PA::$network_info);
// removed $onload param as it is not set anywhere
if (!empty($msg)) {
    for ($counter = 0; $counter < count($msg); $counter++) {
        $message .= $msg[$counter] . "<br>";
    }
}