Example #1
0
 /**
  * @NoAdminRequired
  */
 public function deletePhoto()
 {
     $id = $this->params('id');
     $vcard = ContactsApp::getContactVCard($id);
     unset($vcard->PHOTO);
     VCard::edit($id, $vcard);
     $result = ['status' => 'success', 'data' => ['id' => $id]];
     $response = new JSONResponse();
     $response->setData($result);
     return $response;
 }
 /**
  * @NoAdminRequired
  */
 public function addProbertyToContact()
 {
     $cardId = $this->params('cardId');
     $param = trim(strip_tags($this->params('param')));
     $value = trim(strip_tags($this->params('value')));
     $vcard = ContactsApp::getContactVCard($cardId);
     $vcardMember = 'urn:uuid:' . $vcard->{'UID'};
     $property = $vcard->select($param);
     if (count($property) === 0) {
         //Neu
         $vcard->add($param, $value);
         $iNumber = 1;
     } else {
         $property = array_shift($property);
         $oldValue = stripslashes($property->getValue());
         if (!stristr($oldValue, $value)) {
             $newValue = (string) $oldValue . ',' . $value;
             $property->setValue((string) $newValue);
             $iNumber = 1;
         } else {
             $iNumber = 0;
         }
     }
     VCard::edit($cardId, $vcard);
     //IOS Support $vcardMember
     $iosSupport = $this->configInfo->getUserValue($this->userId, $this->appName, 'iossupport');
     if ($param === 'CATEGORIES' && $iosSupport) {
         if (!is_null($vcard) && !isset($vcard->REV)) {
             $rev = new \DateTime('@' . $groupData['lastmodified']);
             $vcard->REV = $rev->format(\DateTime::W3C);
         }
         $paramsGroupMembers = array();
         $iosGroupMember = $vcard->{'X-ADDRESSBOOKSERVER-MEMBER'};
         $bExist = false;
         if ($iosGroupMember) {
             foreach ($iosGroupMember as $key => $param) {
                 if ($param === $vcardMember) {
                     $bExist = true;
                 }
             }
         } else {
             $vcard->add('X-ADDRESSBOOKSERVER-MEMBER', $vcardMember);
         }
         if (!$bExist) {
             $vcard->add('X-ADDRESSBOOKSERVER-MEMBER', $vcardMember);
         }
         VCard::edit($cardId, $vcard);
     }
     if ($param === 'CATEGORIES') {
         $backgroundColor = ContactsApp::genColorCodeFromText(trim($value));
         $color = ContactsApp::generateTextColor($backgroundColor);
         $aCat['name'] = $value;
         $aCat['color'] = $color;
         $aCat['bgcolor'] = $backgroundColor;
     }
     $params = ['status' => 'success', 'data' => ['cardid' => $cardId, 'iCounter' => $iNumber, 'newcat' => $aCat]];
     $response = new JSONResponse($params);
     return $response;
 }