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