Example #1
0
 /**	 
  * add a new content
  * @param string $format
  * @return string xml/json
  */
 private function contentadd($format)
 {
     $user = $this->checkpassword(true);
     $this->checktrafficlimit($user);
     $categories = EConfig::$data["ocs_categories"];
     $numcats = count($categories);
     if (OCSUser::is_logged()) {
         $data = array();
         $data['name'] = $this->readdata('name', 'text');
         $data['type'] = $this->readdata('type', 'int');
         if ($this->readdata('downloadname1', 'text') != '') {
             $data['downloadname1'] = $this->readdata('downloadname1', 'text');
         }
         if ($this->readdata('downloadlink1', 'text') != '') {
             $data['downloadlink1'] = $this->readdata('downloadlink1', 'text');
         }
         if ($this->readdata('description', 'text') != '') {
             $data['description'] = $this->readdata('description', 'text');
         } else {
             $data['description'] = '...';
         }
         if ($this->readdata('summary', 'text') != '') {
             $data['summary'] = $this->readdata('summary', 'text');
         } else {
             $data['summary'] = '...';
         }
         if ($this->readdata('version', 'text') != '') {
             $data['version'] = $this->readdata('version', 'text');
         } else {
             $data['version'] = '...';
         }
         if ($this->readdata('changelog', 'text') != '') {
             $data['changelog'] = $this->readdata('changelog', 'text');
         } else {
             $data['changelog'] = '...';
         }
         //if($this->readdata('personid','text')<>'')			$data['personid']=$this->readdata('personid','text');
         if ($this->readdata('license', 'int') >= 0 or $this->readdata('license', 'int') < 5) {
             $data['license'] = $this->readdata('license', 'int');
         }
         $data['preview1'] = "http://" . EConfig::$data["ocs"]["host"] . "/template/img/screenshot-unavailable.png";
         $data['preview2'] = "http://" . EConfig::$data["ocs"]["host"] . "/template/img/screenshot-unavailable.png";
         $data['preview3'] = "http://" . EConfig::$data["ocs"]["host"] . "/template/img/screenshot-unavailable.png";
         $data['personid'] = $user;
         if ($data['name'] != '' or $data['type'] < 0 or $data['type'] > $numcats) {
             $content = new OCSContent();
             $content->set_owner(OCSUser::id());
             $content->set_data($data);
             $content->save();
             $xml = array();
             $xml[0]['id'] = $content->id();
             $txt = $this->generatexml($format, 'ok', 100, '', $xml, 'content', '', 2);
         } else {
             $txt = $this->generatexml($format, 'failed', 101, 'please specify all mandatory fields');
         }
     } else {
         $txt = $this->generatexml($format, 'failed', 102, 'no permission to change content');
     }
     echo $txt;
 }