103 |
- |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* Copyright(C) 2009-2019 www.seopanel.in. All rights reserved.
|
|
|
4 |
* @author Geo Varghese
|
|
|
5 |
*
|
|
|
6 |
*/
|
|
|
7 |
class Project extends SeoDiary {
|
|
|
8 |
|
|
|
9 |
var $spTextSA;
|
|
|
10 |
var $spTextPanel;
|
|
|
11 |
|
|
|
12 |
function __construct() {
|
|
|
13 |
parent::__construct();
|
|
|
14 |
$this->spTextSA = $this->getLanguageTexts('siteauditor', $_SESSION['lang_code']);
|
|
|
15 |
}
|
|
|
16 |
|
|
|
17 |
/*
|
|
|
18 |
* show projects list to manage
|
|
|
19 |
*/
|
|
|
20 |
function showProjectsManager($info = '') {
|
|
|
21 |
$userId = isLoggedIn();
|
|
|
22 |
$info ['user_id'] = intval( $info ['user_id'] );
|
|
|
23 |
$pgScriptPath = PLUGIN_SCRIPT_URL;
|
|
|
24 |
$sql = "select sdp.*, w.name as website_name from sd_projects sdp, websites w where sdp.website_id=w.id";
|
|
|
25 |
|
|
|
26 |
if(isAdmin()) {
|
|
|
27 |
$userCtrler = new UserController();
|
|
|
28 |
$userList = $userCtrler->__getAllUsers();
|
|
|
29 |
$this->set( 'userList', $userList );
|
|
|
30 |
|
|
|
31 |
$webSiteCtrler = new WebsiteController();
|
|
|
32 |
$websiteList = $webSiteCtrler->__getAllWebsites();
|
|
|
33 |
$this->set( 'websiteList', $websiteList );
|
|
|
34 |
|
|
|
35 |
if(!empty( $info ['user_id'] )) {
|
|
|
36 |
$pgScriptPath .= "&user_id=" . $info ['user_id'];
|
|
|
37 |
$sql .= " and w.user_id=" . $info ['user_id'];
|
|
|
38 |
$this->set( 'userId', $info ['user_id'] );
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
$this->set( 'isAdmin', 1 );
|
|
|
42 |
} else {
|
|
|
43 |
$sql .= " and w.user_id=$userId";
|
|
|
44 |
$this->set( 'isAdmin', 0 );
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
// pagination setup
|
|
|
48 |
$this->db->query( $sql, true );
|
|
|
49 |
$this->paging->setDivClass( 'pagingdiv' );
|
|
|
50 |
$this->paging->loadPaging( $this->db->noRows, SP_PAGINGNO );
|
|
|
51 |
$pagingDiv = $this->paging->printPages( $pgScriptPath, '', 'scriptDoLoad', 'content', 'layout=ajax' );
|
|
|
52 |
$this->set( 'pagingDiv', $pagingDiv );
|
|
|
53 |
$sql .= " limit " . $this->paging->start . "," . $this->paging->per_page;
|
|
|
54 |
|
|
|
55 |
$projectList = $this->db->select( $sql );
|
|
|
56 |
$this->set( 'list', $projectList );
|
|
|
57 |
$this->set( 'pageNo', $_GET ['pageno'] );
|
|
|
58 |
$this->set('spTextSA', $this->spTextSA);
|
|
|
59 |
$this->pluginRender( 'show_projects_manager' );
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
/*
|
|
|
63 |
* func to create new project
|
|
|
64 |
*/
|
|
|
65 |
function newProject($info = '') {
|
|
|
66 |
$userId = isLoggedIn();
|
|
|
67 |
$webSiteCtrler = new WebsiteController();
|
|
|
68 |
$websiteList = $webSiteCtrler->__getAllWebsites( $userId, true );
|
|
|
69 |
$this->set( 'websiteList', $websiteList );
|
|
|
70 |
$this->pluginRender( 'new_project' );
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
/*
|
|
|
74 |
* func to create project
|
|
|
75 |
*/
|
|
|
76 |
function createProject($listInfo) {
|
|
|
77 |
|
|
|
78 |
$this->set( 'post', $listInfo );
|
|
|
79 |
$errMsg ['website_id'] = formatErrorMsg( $this->validate->checkBlank( $listInfo ['website_id'] ) );
|
|
|
80 |
$errMsg ['name'] = formatErrorMsg( $this->validate->checkBlank( $listInfo ['name'] ) );
|
|
|
81 |
$errMsg ['description'] = formatErrorMsg( $this->validate->checkBlank( $listInfo ['description'] ) );
|
|
|
82 |
|
|
|
83 |
if(! $this->validate->flagErr) {
|
|
|
84 |
if(!$this->__checkProjectExists( $listInfo ['website_id'])) {
|
|
|
85 |
$sql = "insert into sd_projects(website_id, name,description,status)
|
|
|
86 |
values(" . intval( $listInfo ['website_id'] ) . ", '" . addslashes( $listInfo ['name'] ) . "','"
|
|
|
87 |
. addslashes( $listInfo ['description'] ) . "',1)";
|
|
|
88 |
$this->db->query( $sql );
|
|
|
89 |
$this->showProjectsManager();
|
|
|
90 |
exit();
|
|
|
91 |
} else {
|
|
|
92 |
$errMsg ['name'] = formatErrorMsg( $this->spTextSA['projectalreadyexist'] );
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
$this->set( 'errMsg', $errMsg );
|
|
|
97 |
$this->newProject( $listInfo );
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
/*
|
|
|
101 |
* func to edit project
|
|
|
102 |
*/
|
|
|
103 |
function editProject($projectId, $listInfo = '') {
|
|
|
104 |
$userId = isLoggedIn();
|
|
|
105 |
|
|
|
106 |
if(!empty( $projectId )) {
|
|
|
107 |
|
|
|
108 |
if(empty( $listInfo )) {
|
|
|
109 |
$listInfo = $this->__getProjectInfo( $projectId );
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
$this->set( 'post', $listInfo );
|
|
|
113 |
$webSiteCtrler = new WebsiteController();
|
|
|
114 |
$websiteList = $webSiteCtrler->__getAllWebsites( $userId, true );
|
|
|
115 |
$this->set( 'websiteList', $websiteList );
|
|
|
116 |
$this->pluginRender( 'edit_project' );
|
|
|
117 |
}
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
/*
|
|
|
121 |
* func to update project
|
|
|
122 |
*/
|
|
|
123 |
function updateProject($listInfo) {
|
|
|
124 |
|
|
|
125 |
$this->set( 'post', $listInfo );
|
|
|
126 |
$errMsg ['website_id'] = formatErrorMsg( $this->validate->checkBlank( $listInfo ['website_id'] ) );
|
|
|
127 |
$errMsg ['name'] = formatErrorMsg( $this->validate->checkBlank( $listInfo ['name'] ) );
|
|
|
128 |
$errMsg ['description'] = formatErrorMsg( $this->validate->checkBlank( $listInfo ['description'] ) );
|
|
|
129 |
|
|
|
130 |
if(! $this->validate->flagErr) {
|
|
|
131 |
|
|
|
132 |
if($this->__checkProjectExists($listInfo['website_id'], $listInfo ['id'] )) {
|
|
|
133 |
$this->validate->flagErr = true;
|
|
|
134 |
$errMsg ['name'] = formatErrorMsg( $this->spTextSA['projectalreadyexist'] );
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
if(! $this->validate->flagErr) {
|
|
|
138 |
$sql = "update sd_projects set
|
|
|
139 |
website_id = " . intval( $listInfo ['website_id'] ) . ",
|
|
|
140 |
name = '" . addslashes( $listInfo ['name'] ) . "',
|
|
|
141 |
description = '" . addslashes( $listInfo ['description'] ) . "'
|
|
|
142 |
where id=" . intval( $listInfo ['id'] );
|
|
|
143 |
$this->db->query( $sql );
|
|
|
144 |
$this->showProjectsManager();
|
|
|
145 |
exit();
|
|
|
146 |
}
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
$this->set( 'errMsg', $errMsg );
|
|
|
150 |
$this->editProject( $listInfo ['id'], $listInfo );
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
/*
|
|
|
154 |
* func to delete project
|
|
|
155 |
*/
|
|
|
156 |
function deleteProject($projectId) {
|
|
|
157 |
$projectId = intval( $projectId );
|
|
|
158 |
$sql = "delete from sd_projects where id=" . intval( $projectId );
|
|
|
159 |
$this->db->query( $sql );
|
|
|
160 |
$this->showProjectsManager();
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
/*
|
|
|
164 |
* func to change status
|
|
|
165 |
*/
|
|
|
166 |
function __changeStatus($projectId, $status) {
|
|
|
167 |
$projectId = intval( $projectId );
|
|
|
168 |
$status = intval( $status );
|
|
|
169 |
$sql = "update sd_projects set status=$status where id=$projectId";
|
|
|
170 |
$this->db->query( $sql );
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
/*
|
|
|
174 |
* function to check name of project already existing
|
|
|
175 |
*/
|
|
|
176 |
function __checkProjectExists($websiteId, $projectId = 0) {
|
|
|
177 |
$websiteId = intval( $websiteId );
|
|
|
178 |
$projectId = intval($projectId);
|
|
|
179 |
$sql = "select id from sd_projects where website_id=$websiteId";
|
|
|
180 |
$sql .= !empty( $projectId ) ? " and id!=$projectId" : "";
|
|
|
181 |
$listInfo = $this->db->select( $sql, true );
|
|
|
182 |
return !empty( $listInfo ['id'] ) ? $listInfo ['id'] : false;
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
function __getAllProjects($userId = '', $isAdminCheck = false, $searchName = '') {
|
|
|
186 |
$sql = "select p.*,w.name as website_name from sd_projects p,websites w where p.website_id=w.id ";
|
|
|
187 |
if(!$isAdminCheck || !isAdmin() ){
|
|
|
188 |
if(!empty($userId)) $sql .= " and user_id=" . intval($userId);
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
// if search string is not empty
|
|
|
192 |
if (!empty($searchName)) {
|
|
|
193 |
$sql .= " and (name like '%".addslashes($searchName)."%' or url like '%".addslashes($searchName)."%')";
|
|
|
194 |
}
|
|
|
195 |
|
|
|
196 |
$sql .= " order by name";
|
|
|
197 |
$websiteList = $this->db->select($sql);
|
|
|
198 |
return $websiteList;
|
|
|
199 |
}
|
|
|
200 |
|
|
|
201 |
/*
|
|
|
202 |
* func to get project info
|
|
|
203 |
*/
|
|
|
204 |
function __getProjectInfo($projectId) {
|
|
|
205 |
$sql = "select p.*,w.name as website_name from sd_projects p,websites w where p.website_id=w.id and p.id=" . intval( $projectId );
|
|
|
206 |
$info = $this->db->select( $sql, true );
|
|
|
207 |
return $info;
|
|
|
208 |
}
|
|
|
209 |
}
|