1: <?php
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: interface projectWikiImpl {
34:
35: function initialize();
36: function getPluginAppId();
37: function enableObject($enable = true);
38: function getAppMainViewItem();
39: function registerHttpRequestObjects(&$apphandler);
40: function registerAppMenuHandler(&$obj);
41: function setAppMainView(&$pagewrap,&$apphandler,&$baseui,$db,$params_arr);
42: function handleWikiOperation(&$mainhandler,$params);
43: function setWikiView(&$pagewrap,&$mainhandler,&$baseui,$params_arr = null);
44:
45: }
46:
47:
48: class projectWiki implements projectWikiImpl {
49:
50: private $PLUGIN_APP_ID = PROJECT_APP;
51: private $instance;
52: private $enabled;
53: private $menuhandler;
54: public function __construct (){
55: $this->instance = $this;
56: $this->enabled = true;
57: $this->handler = 'wiki';
58: $this->appview = 'bmm_erp_project_wiki';
59:
60: $this->statushandler = new projectStatusReport();
61: $this->timehandler = new projectTimeReport();
62: $this->initialize();
63: }
64:
65: public function initialize(){
66: }
67:
68: public function getPluginAppId(){
69: return $this->PLUGIN_APP_ID;
70: }
71:
72: public function enableObject($enable = true){
73: $this->enabled = $enable;
74: }
75:
76: public function getObjectStatus(){
77: return $this->enabled;
78: }
79:
80: public function getAppMainViewItem(){
81: return $this->appview;
82: }
83:
84: public function registerHttpRequestObjects(&$apphandler){
85: $apphandler->registerHttpRequestObjects(array(get_class($this->instance),$this->appview,"bmm_erp_project_wiki","handleWikiOperation",$this->PLUGIN_APP_ID));
86: }
87:
88: public function registerAppMenuHandler(&$obj){
89: $obj->setMenuObject($this->appview,"wiki",$this->handler,'get');
90: }
91:
92: public function setAppMainView(&$pagewrap,&$mainhandler,&$baseui,$db,$params_arr){
93: $this->setWikiView($pagewrap,$mainhandler,$baseui,$params_arr);
94:
95: }
96:
97: public function handleWikiOperation(&$mainhandler,$params){
98:
99: $param = is_array($params) ? $params['param'] : $params;
100: $write = $mainhandler->verifyApplicationPermission($mainhandler->getAppTargetId(),$mainhandler->getUserId(),null,'WRITE');
101:
102: switch($param){
103: case 'retrieve':
104: $file_id = $mainhandler->filehandler->getAttachmentDataFileIdByName('wiki.html',$mainhandler->getAppId(),$mainhandler->getAppTargetId());
105: if (intval($file_id)){
106: $wiki = $mainhandler->filehandler->getAttachmentDataFile($file_id,null,$mainhandler->getAppId(),$mainhandler->getAppTargetId(),$mainhandler->getSchemaName());
107: }else{
108: $wiki = file_get_contents("../lib/class/plugins/{$this->appview}/lib/wiki.html");
109: }
110: $wiki = preg_replace( "/ajax_reqobj.uri = '.*';/","ajax_reqobj.uri = '{$mainhandler->getHttpUri()}'" ,$wiki ,1,$count);
111: if ($write)
112: $wiki = preg_replace( "/readOnly = true;/","readOnly = false;" ,$wiki ,1,$count);
113: else
114: $wiki = preg_replace( "/readOnly = false;/","readOnly = true;" ,$wiki ,1,$count);
115: return $wiki;
116: break;
117:
118: default:
119: try {
120:
121: $data = $param;
122: $tmp_path = $this->getWikiTmpPath($mainhandler);
123: $this->setWikiTmpFile($tmp_path,$data);
124: $mainhandler->filehandler->setAttName('wiki.html');
125: $mainhandler->filehandler->setAttTmpName($tmp_path);
126: $mainhandler->filehandler->setAttSize(strlen($data));
127: $file_id = $mainhandler->filehandler->syncStorage($mainhandler,
128: 'insert',
129: false,
130: false,
131: null,
132: null,
133: 'project',
134: true);
135: }catch(Exception $e){
136: throw new Exception('invalid_permissions');
137: }
138: break;
139: }
140: }
141:
142: public function setWikiView(&$pagewrap,&$mainhandler,&$baseui,$params_arr = null){
143: global $STATUS_LIST;
144: $actionhandler = $params_arr['actionhandler'];
145: $dataobj = $actionhandler->getDataObject();
146: $actionhandler->setActionParam('disable_status_flow_view',true);
147:
148: echo "
149: <div id='bmm_erp_project_wiki_div'>
150: </div>
151: <iframe id=\"bmm_erp_project_wiki_iframe\" style=\"border:none;width:1024px\" height=\"900px\" src=\"{$pagewrap->getHttpUri()}/?handler=project&contype=httpreq&reqhandler=bmm_erp_project_wiki&reqtype=nojson&request=handleWikiOperation¶m=retrieve\">
152: </iframe>";
153:
154: echo "
155: <script type=\"text/javascript\">
156: bmm_hide_edit_section();
157: $('fitems').disabled = true;
158: bmm_erp_project_wiki.posturi =\"{$pagewrap->getHttpUri()}\";
159: bmm_erp_project_wiki.createWikiFormView();
160: </script>";
161: }
162:
163:
164: private function setWikiTmpFile($file,$data){
165: try {
166: $data = base64_decode($data);
167: $fp = fopen($file, 'w');
168: fwrite($fp, $data);
169: fclose($fp);
170: }catch(Exception $e){
171: error_log("FAILED TO OPEN $file");
172:
173: }
174: }
175:
176: private function getWikiTmpPath(&$mainhandler){
177: return "/tmp/wki{$mainhandler->getAppId()}_{$mainhandler->getAppTargetId()}_{$mainhandler->getSchemaName()}";
178: }
179:
180: private function (){
181: return file_get_contents("../lib/class/plugins/{$this->appview}/lib/wiki_head.html");
182:
183: }
184: }?>
185: