forked from easysoft/zentaopms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.php
197 lines (179 loc) · 6.15 KB
/
control.php
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
<?php
/**
* The control file of webapp of ZenTaoPMS.
*
* @copyright Copyright 2009-2013 QingDao Nature Easy Soft Network Technology Co,LTD (www.cnezsoft.com)
* @license LGPL (http://www.gnu.org/licenses/lgpl.html)
* @author Yidong Wang <[email protected]>
* @package webapp
* @version $Id$
* @link http://www.zentao.net
*/
class webapp extends control
{
/**
* Index for webapp.
*
* @param int $module
* @access public
* @return void
*/
public function index($module = 0)
{
$module = (int)$module;
$webapps = $this->webapp->getLocalApps('id', $module);
$this->webapp->setMenu($module);
$this->view->title = $this->lang->webapp->common;
$this->view->webapps = $webapps;
$this->view->moduleTree = $this->loadModel('tree')->getTreeMenu(0, 'webapp', 0, array('treeModel', 'createWebappLink'));
$this->view->module = $module;
$this->display();
}
/**
* Obtain web app.
*
* @param string $type
* @param string $param
* @param int $recTotal
* @param int $recPerPage
* @param int $pageID
* @access public
* @return void
*/
public function obtain($type = 'byUpdatedTime', $param = '', $recTotal = 0, $recPerPage = 20, $pageID = 1)
{
$this->webapp->setMenu();
/* Init vars. */
$type = strtolower($type);
$moduleID = $type == 'bymodule' ? (int)$param : 0;
$webapps = array();
$pager = null;
/* Set the key. */
if($type == 'bysearch') $param = helper::safe64Encode($this->post->key);
/* Get results from the api. */
$recPerPage = $this->cookie->pagerWebappObtain ? $this->cookie->pagerWebappObtain : $recPerPage;
$results = $this->webapp->getAppsByAPI($type, $param, $recTotal, $recPerPage, $pageID);
if($results)
{
$this->app->loadClass('pager', $static = true);
$pager = new pager($results->dbPager->recTotal, $results->dbPager->recPerPage, $results->dbPager->pageID);
$webapps = $results->webapps;
}
$this->view->title = $this->lang->webapp->common . $this->lang->colon . $this->lang->webapp->obtain;
$this->view->position[] = $this->lang->webapp->obtain;
$this->view->moduleTree = $this->webapp->getModulesByAPI();
$this->view->webapps = $webapps;
$this->view->installeds = $this->webapp->getLocalApps('appid');
$this->view->pager = $pager;
$this->view->tab = 'obtain';
$this->view->type = $type;
$this->view->moduleID = $moduleID;
$this->display();
}
/**
* Edit web app.
*
* @param int $webappID
* @access public
* @return void
*/
public function edit($webappID)
{
if($_POST)
{
$this->webapp->update($webappID);
if(dao::isError())die(js::error(dao::getError()));
die(js::reload('parent.parent'));
}
$this->view->title = $this->lang->webapp->common . $this->lang->colon . $this->lang->webapp->edit;
$this->view->modules = $this->loadModel('tree')->getOptionMenu(0, 'webapp');
$this->view->webapp = $this->webapp->getLocalAppByID($webappID);
$this->display();
}
/**
* Create web app.
*
* @access public
* @return void
*/
public function create()
{
if($_POST)
{
$webappID = $this->webapp->create();
if(dao::isError())die(js::error(dao::getError()));
die(js::locate(inlink('index'), 'parent'));
}
$this->webapp->setMenu();
$this->view->title = $this->lang->webapp->common . $this->lang->colon . $this->lang->webapp->create;
$this->view->position[] = $this->lang->webapp->create;
$this->view->modules = $this->loadModel('tree')->getOptionMenu(0, 'webapp');
$this->display();
}
/**
* View app.
*
* @param int $webappID
* @param string $type
* @access public
* @return void
*/
public function view($webappID, $type = 'local')
{
$this->view->title = $this->lang->webapp->common . $this->lang->colon . $this->lang->webapp->edit;
$this->view->modules = $this->loadModel('tree')->getOptionMenu(0, 'webapp');
$this->view->users = $this->loadModel('user')->getPairs('noletter');
$this->view->webapp = $type == 'local' ? $this->webapp->getLocalAppByID($webappID) : $this->webapp->getAppInfoByAPI($webappID)->webapp;
$this->view->type = $type;
$this->display();
}
/**
* Install web app.
*
* @param int $webappID
* @access public
* @return void
*/
public function install($webappID)
{
if($_POST)
{
$result = $this->webapp->install($webappID);
if(dao::isError())
{
echo js::error(dao::getError());
die(js::reload('parent'));
}
echo js::alert($this->lang->webapp->successInstall);
die(js::closeModal('parent.parent'));
}
$this->view->title = $this->lang->webapp->common . $this->lang->colon . $this->lang->webapp->install;
$this->view->modules = $this->webapp->getModules();
$this->display();
}
/**
* uninstall web app.
*
* @param int $webappID
* @param string $confirm
* @access public
* @return void
*/
public function uninstall($webappID, $confirm = 'no')
{
if($confirm == 'no') die(js::confirm($this->lang->webapp->confirmDelete, inlink('uninstall', "webappID=$webappID&confirm=yes")));
$this->dao->delete()->from(TABLE_WEBAPP)->where('id')->eq($webappID)->exec();
die(js::reload('parent'));
}
/**
* Views add one by ajax.
*
* @param int $webappID
* @access public
* @return void
*/
public function ajaxAddView($webappID)
{
$this->dao->update(TABLE_WEBAPP)->set('views=views+1')->where('id')->eq($webappID)->exec();
}
}