Ejemplo n.º 1
0
 /**
  * @NoAdminRequired
  */
 public function deleteContact()
 {
     $pIds = $this->params('id');
     $aPid = explode(',', $pIds);
     $oldValue = '';
     $fullname = '';
     $addrId = 0;
     foreach ($aPid as $id) {
         $vcard = ContactsApp::getContactVCard($id);
         $property = $vcard->select('CATEGORIES');
         if (count($property) === 0) {
             $oldValue = '';
         } else {
             $property = array_shift($property);
             $oldValue = stripslashes($property->getValue());
         }
         $carddata = VCard::find($id);
         $fullname = strtoupper(substr($carddata['fullname'], 0, 1));
         $addrId = $carddata['addressbookid'];
         VCard::delete($id);
     }
     $params = ['status' => 'success', 'data' => ['id' => $aPid[0], 'groups' => $oldValue, 'letter' => $fullname, 'count' => count($aPid), 'addrId' => $addrId]];
     $response = new JSONResponse($params);
     return $response;
 }
 /**
  * @NoAdminRequired
  */
 public function prepareIosGroups()
 {
     $pGroups = $this->params('agroups');
     $pAddrBookId = $this->params('aid');
     if ($pAddrBookId > 0) {
         $existIosGroups = ContactsApp::getIosGroups();
         $iCountExist = count($pGroups);
         $iCountIosExist = count($existIosGroups);
         if ($iCountExist < $iCountIosExist) {
             //Group Delete
             foreach ($existIosGroups as $key => $value) {
                 if (!array_key_exists($key, $pGroups)) {
                     VCard::delete($value['id']);
                 }
             }
         }
         if ($iCountExist > $iCountIosExist) {
             //Group Added
             $newGroup = array();
             foreach ($pGroups as $key => $value) {
                 if (!array_key_exists($key, $existIosGroups)) {
                     $newGroup[] = $key;
                 }
             }
             foreach ($newGroup as $val) {
                 $uid = substr(md5(rand() . time()), 0, 10);
                 $appinfo = \OCP\App::getAppInfo($this->appName);
                 $appversion = \OCP\App::getAppVersion($this->appName);
                 $prodid = '-//ownCloud//NONSGML ' . $appinfo['name'] . ' ' . $appversion . '//EN';
                 $vcard = new \Sabre\VObject\Component\VCard(array('PRODID' => $prodid, 'VERSION' => '3.0', 'UID' => $uid));
                 $vcard->N = $val;
                 $vcard->FN = $val;
                 //X-ADDRESSBOOKSERVER-KIND:group
                 $vcard->{'X-ADDRESSBOOKSERVER-KIND'} = 'group';
                 $id = VCard::add($pAddrBookId, $vcard, null, true);
             }
         }
         $params = ['status' => 'success'];
         $response = new JSONResponse($params);
         return $response;
     }
     //END $addrBk
 }
Ejemplo n.º 3
0
 /**
  * @NoAdminRequired
  */
 public function deleteContact()
 {
     $pId = $this->params('id');
     $vcard = ContactsApp::getContactVCard($pId);
     $property = $vcard->select('CATEGORIES');
     if (count($property) === 0) {
         $oldValue = '';
     } else {
         $property = array_shift($property);
         $oldValue = stripslashes($property->getValue());
     }
     $carddata = VCard::find($pId);
     $fullname = strtoupper(substr($carddata['fullname'], 0, 1));
     VCard::delete($pId);
     $params = ['status' => 'success', 'data' => ['id' => $pId, 'groups' => $oldValue, 'letter' => $fullname]];
     $response = new JSONResponse($params);
     return $response;
 }