コード例 #1
0
/**
 * Saves calendar data
 * @return void
 * @access private
 */
function writecalendardata()
{
    global $calendardata, $username, $data_dir, $year, $color;
    $filetmp = getHashedFile($username, $data_dir, "{$username}.{$year}.cal.tmp");
    $filename = getHashedFile($username, $data_dir, "{$username}.{$year}.cal");
    $fp = fopen($filetmp, "w");
    if ($fp) {
        while ($calfoo = each($calendardata)) {
            while ($calbar = each($calfoo['value'])) {
                $calfoobar = $calendardata[$calfoo['key']][$calbar['key']];
                array_walk($calfoobar, 'calendar_encodedata');
                /**
                 * Make sure that reminder field is set. Calendar forms don't implement it, 
                 * but it is still used for calendar data. Backwards compatibility.
                 */
                if (!isset($calfoobar['reminder'])) {
                    $calfoobar['reminder'] = '';
                }
                $calstr = "{$calfoo['key']}|{$calbar['key']}|{$calfoobar['length']}|{$calfoobar['priority']}|{$calfoobar['title']}|{$calfoobar['message']}|{$calfoobar['reminder']}\n";
                if (sq_fwrite($fp, $calstr, 4096) === FALSE) {
                    error_box(_("Could not write calendar file %s", "{$username}.{$year}.cal.tmp"), $color);
                }
            }
        }
        fclose($fp);
        @unlink($filename);
        rename($filetmp, $filename);
    }
}
コード例 #2
0
 /**
  * Add address
  * @param array $userdata new data
  * @return bool
  */
 function add($userdata)
 {
     if (!$this->writeable) {
         return $this->set_error(_("Address book is read-only"));
     }
     /* See if user exists already */
     $ret = $this->lookup($userdata['nickname']);
     if (!empty($ret)) {
         // i18n: don't use html formating in translation
         return $this->set_error(sprintf(_("User \"%s\" already exists"), $ret['nickname']));
     }
     /* Here is the data to write */
     $data = $this->quotevalue($userdata['nickname']) . '|' . $this->quotevalue($userdata['firstname']) . '|' . $this->quotevalue(!empty($userdata['lastname']) ? $userdata['lastname'] : '') . '|' . $this->quotevalue($userdata['email']) . '|' . $this->quotevalue(!empty($userdata['label']) ? $userdata['label'] : '');
     /* Strip linefeeds */
     $data = ereg_replace("[\r\n]", ' ', $data);
     /**
      * Make sure that entry fits into allocated record space.
      * One byte is reserved for linefeed
      */
     if (strlen($data) >= $this->line_length) {
         return $this->set_error(_("Address book entry is too big"));
     }
     /* Add linefeed at end */
     $data = $data . "\n";
     /* Reopen file, just to be sure */
     $this->open(true);
     if (!$this->writeable) {
         return $this->set_error(_("Address book is read-only"));
     }
     /* Lock the file */
     if (!$this->lock()) {
         return $this->set_error(_("Could not lock datafile"));
     }
     /* Write */
     $r = sq_fwrite($this->filehandle, $data);
     /* Unlock file */
     $this->unlock();
     /* Test write result */
     if ($r === FALSE) {
         /* Fail */
         $this->set_error(_("Write to address book failed"));
         return FALSE;
     }
     return TRUE;
 }
コード例 #3
0
/**
 * Write the User Signature.
 */
function setSig($data_dir, $username, $number, $value)
{
    // Limit signature size to 64KB (database BLOB limit)
    if (strlen($value) > 65536) {
        error_option_save(_("Signature is too big."));
        return;
    }
    $filename = getHashedFile($username, $data_dir, "{$username}.si{$number}");
    /* Open the file for writing, or else display an error to the user. */
    if (!($file = @fopen("{$filename}.tmp", 'w'))) {
        logout_error(sprintf(_("Signature file, %s, could not be opened. Contact your system administrator to resolve this issue."), $filename . '.tmp'));
        exit;
    }
    if (sq_fwrite($file, $value) === FALSE) {
        logout_error(sprintf(_("Signature file, %s, could not be written. Contact your system administrator to resolve this issue."), $filename . '.tmp'));
        exit;
    }
    fclose($file);
    if (!@copy($filename . '.tmp', $filename)) {
        logout_error(sprintf(_("Signature file, %s, could not be copied from temporary file, %s. Contact your system administrator to resolve this issue."), $filename, $filename . '.tmp'));
        exit;
    }
    @unlink($filename . '.tmp');
    @chmod($filename, 0600);
}
コード例 #4
0
 function add($userdata)
 {
     if (!$this->writeable) {
         return $this->set_error(_("Addressbook is read-only"));
     }
     /* See if user exists already */
     $ret = $this->lookup($userdata['nickname']);
     if (!empty($ret)) {
         return $this->set_error(sprintf(_("User '%s' already exist"), $ret['nickname']));
     }
     /* Here is the data to write */
     $data = $this->quotevalue($userdata['nickname']) . '|' . $this->quotevalue($userdata['firstname']) . '|' . $this->quotevalue($userdata['lastname']) . '|' . $this->quotevalue($userdata['email']) . '|' . $this->quotevalue($userdata['label']);
     /* Strip linefeeds */
     $data = ereg_replace("[\r\n]", ' ', $data);
     /* Add linefeed at end */
     $data = $data . "\n";
     /* Reopen file, just to be sure */
     $this->open(true);
     if (!$this->writeable) {
         return $this->set_error(_("Addressbook is read-only"));
     }
     /* Lock the file */
     if (!$this->lock()) {
         return $this->set_error(_("Could not lock datafile"));
     }
     /* Write */
     $r = sq_fwrite($this->filehandle, $data);
     /* Unlock file */
     $this->unlock();
     /* Test write result */
     if ($r === FALSE) {
         /* Fail */
         $this->set_error(_("Write to addressbook failed"));
         return FALSE;
     }
     return TRUE;
 }