Beispiel #1
0
    public static function CheckPrincipals($sUserName)
    {
        if (trim($sUserName) !== '') {
            $oPdo = \CApi::GetPDO();
            $dbPrefix = \CApi::GetSettingsConf('Common/DBPrefix');
            $sPrincipal = \afterlogic\DAV\Constants::PRINCIPALS_PREFIX . '/' . $sUserName;
            $oStmt = $oPdo->prepare('SELECT id FROM ' . $dbPrefix . Constants::T_PRINCIPALS . ' WHERE uri = ? LIMIT 1');
            $oStmt->execute(array($sPrincipal));
            if (count($oStmt->fetchAll()) === 0) {
                $oStmt = $oPdo->prepare('INSERT INTO ' . $dbPrefix . Constants::T_PRINCIPALS . '
						(uri,email,displayname) VALUES (?, ?, ?)');
                try {
                    $oStmt->execute(array($sPrincipal, $sUserName, ''));
                } catch (Exception $e) {
                }
            }
            $oStmt = $oPdo->prepare('SELECT principaluri FROM ' . $dbPrefix . Constants::T_CALENDARS . '
					WHERE principaluri = ?');
            $oStmt->execute(array($sPrincipal));
            if (count($oStmt->fetchAll()) === 0) {
                $oStmt = $oPdo->prepare('INSERT INTO ' . $dbPrefix . Constants::T_CALENDARS . '
						(principaluri, displayname, uri, description, components, ctag, calendarcolor)
						VALUES (?, ?, ?, ?, ?, 1, ?)');
                $oAccount = self::GetAccountByLogin($sUserName);
                $oStmt->execute(array($sPrincipal, \CApi::ClientI18N('CALENDAR/CALENDAR_DEFAULT_NAME', $oAccount), \Sabre\DAV\UUIDUtil::getUUID(), '', 'VEVENT,VTODO', Constants::CALENDAR_DEFAULT_COLOR));
            }
            $oStmt = $oPdo->prepare('SELECT principaluri FROM ' . $dbPrefix . Constants::T_CALENDARS . '
					WHERE principaluri = ? and uri = ? LIMIT 1');
            $oStmt->execute(array($sPrincipal, Constants::CALENDAR_DEFAULT_NAME));
            if (count($oStmt->fetchAll()) !== 0) {
                $oStmt = $oPdo->prepare('UPDATE ' . $dbPrefix . Constants::T_CALENDARS . '
						SET uri = ? WHERE principaluri = ? and uri = ?');
                $oStmt->execute(array(\Sabre\DAV\UUIDUtil::getUUID(), $sPrincipal, Constants::CALENDAR_DEFAULT_NAME));
            }
            $oStmt = $oPdo->prepare('SELECT principaluri FROM ' . $dbPrefix . Constants::T_ADDRESSBOOKS . '
					WHERE principaluri = ? and uri = ? LIMIT 1');
            $oStmt->execute(array($sPrincipal, Constants::ADDRESSBOOK_DEFAULT_NAME));
            $bHasDefaultAddressbooks = count($oStmt->fetchAll()) != 0;
            $oStmt->execute(array($sPrincipal, Constants::ADDRESSBOOK_DEFAULT_NAME_OLD));
            $bHasOldDefaultAddressbooks = count($oStmt->fetchAll()) != 0;
            $oStmt->execute(array($sPrincipal, Constants::ADDRESSBOOK_COLLECTED_NAME));
            $bHasCollectedAddressbooks = count($oStmt->fetchAll()) != 0;
            $stmt1 = $oPdo->prepare('INSERT INTO ' . $dbPrefix . Constants::T_ADDRESSBOOKS . '
					(principaluri, displayname, uri, description, ctag)
					VALUES (?, ?, ?, ?, 1)');
            if (!$bHasDefaultAddressbooks) {
                if ($bHasOldDefaultAddressbooks) {
                    $oStmt = $oPdo->prepare('UPDATE ' . $dbPrefix . Constants::T_ADDRESSBOOKS . '
							SET uri = ? WHERE principaluri = ? and uri = ?');
                    $oStmt->execute(array(Constants::ADDRESSBOOK_DEFAULT_NAME, $sPrincipal, Constants::ADDRESSBOOK_DEFAULT_NAME_OLD));
                } else {
                    $stmt1->execute(array($sPrincipal, Constants::ADDRESSBOOK_DEFAULT_DISPLAY_NAME, Constants::ADDRESSBOOK_DEFAULT_NAME, Constants::ADDRESSBOOK_DEFAULT_DISPLAY_NAME));
                }
            }
            if (!$bHasCollectedAddressbooks) {
                $stmt1->execute(array($sPrincipal, Constants::ADDRESSBOOK_COLLECTED_DISPLAY_NAME, Constants::ADDRESSBOOK_COLLECTED_NAME, Constants::ADDRESSBOOK_COLLECTED_DISPLAY_NAME));
            }
        }
    }
Beispiel #2
0
 /**
  * @param CAccount $oAccount = null
  * @return bool
  */
 public function isMobileSyncSupported($oAccount = null)
 {
     $bResult = $this->isNotLite() && $this->isDavSupported() && ($this->isContactsSupported() || $this->isGlobalContactsSupported() || $this->isCalendarSupported() || $this->isHelpdeskSupported());
     if ($bResult) {
         $bResult = \CApi::GetSettingsConf('Common/EnableMobileSync');
     }
     if ($bResult && $oAccount) {
         $bResult = $oAccount->User->getCapa(ECapa::MOBILE_SYNC) && ($this->isContactsSupported($oAccount) || $this->isGlobalContactsSupported($oAccount) || $this->isCalendarSupported($oAccount) || $this->isHelpdeskSupported($oAccount));
     }
     return $bResult;
 }