You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

350 lines
11 KiB

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
use app\core\utils\Response;
class Personalization extends MY_Controller {
public function __construct()
{
$this->my_parent_controller();
$this->load->model('personalization_model');
$this->load->model('event_model');
Response::handleSessionTimeout("bo");
//$this->load_language_backoffice();
$this->lang->load('backoffice/personalization', 'fr');
//origin folders
$this->hstroke_origin = origin_folders('hstroke');
$this->banner_origin = origin_folders('banner');
//banner and heartstroke folder
$this->banner_folder = banner_bundle();
$this->hstroke_folder = hstroke_bundle();
}
public function create_reg_form_rules()
{
$arr = [];
foreach ($this->personalization_model->get_user_subscriber_reg_form() as $key => $value) {
array_push($arr, array(
"name" => $value->name,
"length" => 3,
"required" => ( $value->is_required > 0 ? true : false ),
"status" => ( $value->display_status > 0 ? "display" : "hidden" )
) );
}
output_to_json($this,$arr);
}
public function get_reg_form()
{
$this->arr = [];
foreach ($this->personalization_model->get_user_subscriber_reg_form(1) as $key => $value) {
$arr[] = $value;
}
output_to_json($this, $arr);
}
public function update_reg_form()
{
$this->arr = [];
$this->arr['affected_rows'] = $this->personalization_model->update_user_subscriber_reg_form() >= 0 ? $this->lang->line("update_successful") : $this->lang->line("update_error");
output_to_json($this, $this->arr);
}
public function upload_description()
{
$this->arr['message'] = "success";
$this->personalization_model->upload_new_banner(
array(
'description' => $_POST['description']
)
);
output_to_json($this,$this->arr);
}
public function upload_banner()
{
$domain = $_SERVER['HTTP_HOST'];
$university_id = (int) $this->event_model->get_university_id_by_domain($domain);
$data = $_POST['imagebase64'];
$description = $_POST['description'];
list($type, $data) = explode(';', $data);
list(, $data) = explode(',', $data);
$data = base64_decode($data);
$imageName = time().'.png';
$origin = $this->banner_origin;
if( (is_dir($origin) && is_writable($origin)) ){
file_put_contents($origin.$imageName, $data);
$this->arr['message'] = "success";
$this->arr['banner'] = $imageName;
$this->arr['description'] = $description;
$this->personalization_model->upload_new_banner(
array(
'image' => $imageName,
'description' => $description,
'user_cpay' => $university_id
)
);
output_to_json($this,$this->arr);
}else{
$this->arr['message'] = "error";
$this->arr['banner'] = $data;
output_to_json($this,$this->arr);
}
}
public function get_banner()
{
output_to_json($this,$this->personalization_model->upload_get_banner());
}
public function append_mentions_legales()
{
output_to_json($this,$this->personalization_model->append_mentions_legales());
}
public function update_mentions_legales()
{
if( $this->personalization_model->update_mentions_legales() >= 0 )
{
$arr['message'] = $this->lang->line("update_successful");
$arr['mtype'] = "success";
}
else
{
$arr['message'] = $this->lang->line("update_error");
$arr['mtype'] = "error";
}
output_to_json($this, $arr );
}
public function append_privacy()
{
output_to_json($this,$this->personalization_model->append_privacy());
}
public function update_privacy()
{
if( $this->personalization_model->update_privacy() >= 0 )
{
$arr['message'] = $this->lang->line("update_successful");
$arr['mtype'] = "success";
}
else
{
$arr['message'] = $this->lang->line("update_error");
$arr['mtype'] = "error";
}
output_to_json($this, $arr );
}
public function upload_logo()
{
$origin = $this->hstroke_origin;
$domain = $_SERVER['HTTP_HOST'];
$university_id = (int) $this->event_model->get_university_id_by_domain($domain);
if( (is_dir($origin) && is_writable($origin)) ){
$name = $_FILES['logo']['name'];
$tmp = $_FILES['logo']['tmp_name'];
$error = $_FILES['logo']['error'] ;
$info = getimagesize($tmp);
$rename = round(microtime(true)).'.'.end( explode(".", $_FILES["logo"]["name"]) );
$store = $this->hstroke_origin.$rename;
if ($error !== UPLOAD_ERR_OK) {
output_to_json($this, array(
"mtype" => "error" ,
"message" => $this->lang->line("upload_error_code") .$error
));
}
if ($info === FALSE) {
output_to_json($this, array(
"mtype" => "error" ,
"message" => $this->lang->line("unable_determine_image_type")
));
}
if (($info[2] !== IMAGETYPE_GIF) && ($info[2] !== IMAGETYPE_JPEG) && ($info[2] !== IMAGETYPE_PNG)) {
output_to_json($this, array(
"mtype" => "error" ,
"message" => $this->lang->line("upload_extensions_like")
));
}
else if( move_uploaded_file($tmp, $store) ){
$this->personalization_model->insert_logo( array(
'image' => $rename,
'status' => 1,
'user_cpay' => $university_id
));
output_to_json($this, array(
'image' => $this->hstroke_folder.$rename,
"mtype" => "success" ,
"message" => $this->lang->line("success_upload")
));
}
}
}
public function upload_get_logo()
{
// $result = $this->hstroke_folder.$this->personalization_model->get_heartstroke();
// echo $result;
output_to_json($this,
$this->hstroke_folder.$this->personalization_model->get_logo()['image']
);
}
//announcement
public function get_announcement()
{
$res = $this->personalization_model->listannouncements();
output_to_json($this,$res);
}
public function get_specific_announcement()
{
$q = $this->input->post('id');
$res = $this->personalization_model->get_announcement($q);
output_to_json($this,$res);
}
public function save_announcement()
{
$random = generateRandomString();
if( $this->personalization_model->save_announcement($random) >= 0 )
{
$arr['message'] = $this->lang->line("update_successful");
$arr['mtype'] = "success";
}
else
{
$arr['message'] = $this->lang->line("update_error");
$arr['mtype'] = "error";
}
output_to_json($this, $arr );
}
public function check_enable_announcement()
{
$res = $this->personalization_model->check_enable_announcement();
if($res=='full'){
output_to_json($this,'full');
}else{
output_to_json($this,$res);
}
}
public function enable_announcement()
{
$q = $this->input->post('id');
$random = generateRandomString();
$res = $this->personalization_model->enable_announcement($q,$random);
if($res=='full'){
output_to_json($this,'full');
}else{
output_to_json($this,$res);
}
}
public function disable_announcement()
{
$q = $this->input->post('id');
$res = $this->personalization_model->disable_announcement($q);
output_to_json($this,$res);
}
public function delete_announcement()
{
$q = $this->input->post('id');
$res = $this->personalization_model->delete_announcement($q);
output_to_json($this,$res);
}
public function update_announcement()
{
$q = $this->input->post('id');
$title = $this->input->post('title');
$date = $this->input->post('date');
$content = $this->input->post('content');
$random = generateRandomString();
$res = $this->personalization_model->update_announcement($q,$title,$date,$content,$random);
output_to_json($this,$res);
}
public function post_acceptor(){
upload_tinymce_image();
// $accepted_origins = array("http://localhost", "http://127.0.0.1", "http://www.sumker.com");
//
// $imageFolder = "resources/images/backoffice/announcement/";
// var_dump($_FILES);
// reset ($_FILES);
// $temp = current($_FILES);
//
// if (is_uploaded_file($temp['tmp_name'])){
//
// if (isset($_SERVER['HTTP_ORIGIN'])) {
// // same-origin requests won't set an origin. If the origin is set, it must be valid.
// if (in_array($_SERVER['HTTP_ORIGIN'], $accepted_origins)) {
// header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
// } else {
// header("HTTP/1.1 403 Origin Denied");
// return;
// }
// }
//
// /*
// If your script needs to receive cookies, set images_upload_credentials : true in
// the configuration and enable the following two headers.
// */
// // header('Access-Control-Allow-Credentials: true');
// // header('P3P: CP="There is no P3P policy."');
//
// // Sanitize input
// if (preg_match("/([^\w\s\d\-_~,;:\[\]\(\).])|([\.]{2,})/", $temp['name'])) {
// header("HTTP/1.1 400 Invalid file name.");
// return;
// }
//
// // Verify extension
// if (!in_array(strtolower(pathinfo($temp['name'], PATHINFO_EXTENSION)), array("gif", "jpg", "png"))) {
// header("HTTP/1.1 400 Invalid extension.");
// return;
// }
//
// // Accept upload if there was no origin, or if it is an accepted origin
// $filetowrite = $imageFolder . $temp['name'];
// move_uploaded_file($temp['tmp_name'], $filetowrite);
//
// // Respond to the successful upload with JSON.
// // Use a location key to specify the path to the saved image resource.
// // { location : '/your/uploaded/image/file'}
// // $img = [
// // 'location' => base_url('blog_img/') . $temp['name']
// // ];
// $img = [
// 'location' => base_url('resources/images/backoffice/announcement/') . $temp['name']
// ];
// // echo $this->response->setJSON($img);
// output_to_json($this,$img);
// } else {
// // Notify editor that the upload failed
// header("HTTP/1.1 500 Server Error");
// }
}
public function update_homepage_title()
{
$title = $this->input->post("title");
if( $this->personalization_model->update_homepage_title($title) >= 0 )
{
$arr['message'] = $this->lang->line("update_successful");
$arr['mtype'] = "success";
}
output_to_json($this, $arr );
}
public function get_homepage_title()
{
$title = $this->personalization_model->get_homepage_title();
output_to_json($this, $title);
}
}