Пример #1
0
 /**
  * Add Medias for User
  *
  * <code>
  * $media_data = array(
  * 	*string 'userid => 'User ID',
  * 	array 'medias' => array(
  * 		string 'mediaid' => 'Medi ID',
  * 		string 'mediatypeid' => 'media type ID',
  * 		string 'sendto' => 'address',
  * 		int 'severity' => 'severity',
  * 		int 'active' => 'active',
  * 		string 'period' => 'period',
  * 		)
  * );
  * </code>
  *
  * @static
  * @param array $media_data 
  * @return boolean
  */
 public static function updateMedia($media_data)
 {
     $result = false;
     $userid = $media_data['userid'];
     foreach ($media_data['medias'] as $media) {
         $result = update_media($media['mediaid'], $userid, $media['mediatypeid'], $media['sendto'], $media['severity'], $media['active'], $media['period']);
         if (!$result) {
             break;
         }
     }
     if ($result) {
         return true;
     } else {
         self::$error = array('error' => ZBX_API_ERROR_INTERNAL, 'data' => 'Internal zabbix error');
         return false;
     }
 }
Пример #2
0
/**
* import record into database
*
* this function will parse the given gedcom record and add it to the database
* @param string $gedrec the raw gedcom record to parse
* @param boolean $update whether or not this is an updated record that has been accepted
*/
function import_record($gedrec, $update)
{
    global $xtype, $TBLPREFIX, $GEDCOM_FILE, $FILE, $pgv_lang, $USE_RIN;
    global $place_id, $WORD_WRAPPED_NOTES, $GEDCOMS, $MAX_IDS, $fpnewged, $GEDCOM, $GENERATE_UIDS;
    global $gBitDb, $gGedcom;
    $FILE = $gGedcom->mGedcomName;
    // Escaped @ signs (only if importing from file)
    if (!$update) {
        $gedrec = str_replace('@@', '@', $gedrec);
    }
    // Standardise gedcom format
    $gedrec = reformat_record_import($gedrec);
    // import different types of records
    if (preg_match('/^0 @(' . PGV_REGEX_XREF . ')@ (' . PGV_REGEX_TAG . ')/', $gedrec, $match) > 0) {
        list(, $gid, $type) = $match;
        // check for a _UID, if the record doesn't have one, add one
        if ($GENERATE_UIDS && !strpos($gedrec, "\n1 _UID ")) {
            $gedrec .= "\n1 _UID " . uuid();
        }
    } elseif (preg_match('/0 (' . PGV_REGEX_TAG . ')/', $gedrec, $match)) {
        $gid = $match[1];
        $type = $match[1];
    } else {
        echo $pgv_lang['invalid_gedformat'], '<br /><pre>', $gedrec, '</pre>';
        return;
    }
    // keep track of the max id for each type as they are imported
    if (!isset($MAX_IDS)) {
        $MAX_IDS = array();
    }
    if (preg_match('/(\\d+)/', $gid, $match)) {
        $idnum = (int) $match[1];
    } else {
        $idnum = 0;
    }
    if (isset($MAX_IDS[$type])) {
        $MAX_IDS[$type] = max($MAX_IDS[$type], $idnum);
    } else {
        $MAX_IDS[$type] = $idnum;
    }
    $newrec = update_media($gid, $gedrec, $update);
    if ($newrec != $gedrec) {
        $gedrec = $newrec;
        // make sure we have the correct media id
        if (preg_match('/0 @(' . PGV_REGEX_XREF . ')@ (' . PGV_REGEX_TAG . ')/', $gedrec, $match)) {
            list(, $gid, $type) = $match;
        } else {
            echo $pgv_lang['invalid_gedformat'], '<br /><pre>', $gedrec, '</pre>';
            return;
        }
    }
    switch ($type) {
        case 'INDI':
            $record = new Person($gedrec);
            break;
        case 'FAM':
            $record = new Family($gedrec);
            break;
        case 'SOUR':
            $record = new Source($gedrec);
            break;
        case 'REPO':
            $record = new Repository($gedrec);
            break;
        case 'OBJE':
            $record = new Media($gedrec);
            break;
        default:
            $record = new GedcomRecord($gedrec);
            $type = $record->getType();
            break;
    }
    // Just in case the admin has blocked themself from seeing names!
    $record->disp = true;
    $record->dispname = true;
    // Update the cross-reference/index tables.
    $ged_id = $gGedcom->mGEDCOMId;
    $xref = $gid;
    update_places($xref, $ged_id, $gedrec);
    update_dates($xref, $ged_id, $gedrec);
    update_links($xref, $ged_id, $gedrec);
    update_rlinks($xref, $ged_id, $gedrec);
    update_names($xref, $ged_id, $record);
    switch ($type) {
        case 'INDI':
            if ($USE_RIN && preg_match('/\\n1 RIN (.+)/', $gedrec, $match)) {
                $rin = $match[1];
            } else {
                $rin = $xref;
            }
            $param = array($xref, $ged_id, $rin, is_dead($gedrec, '', true), $record->getSex(), $gedrec);
            $gBitDb->query("INSERT INTO {$TBLPREFIX}individuals (i_id, i_file, i_rin, i_isdead, i_sex, i_gedcom) VALUES (?,?,?,?,?,?)", $param);
            break;
        case 'FAM':
            if (preg_match('/\\n1 HUSB @(' . PGV_REGEX_XREF . ')@/', $gedrec, $match)) {
                $husb = $match[1];
            } else {
                $husb = '';
            }
            if (preg_match('/\\n1 WIFE @(' . PGV_REGEX_XREF . ')@/', $gedrec, $match)) {
                $wife = $match[1];
            } else {
                $wife = '';
            }
            if ($nchi = preg_match_all('/\\n1 CHIL @(' . PGV_REGEX_XREF . ')@/', $gedrec, $match)) {
                $chil = implode(';', $match[1]) . ';';
            } else {
                $chil = '';
            }
            if (preg_match('/\\n1 NCHI (\\d+)/', $gedrec, $match)) {
                $nchi = max($nchi, $match[1]);
            }
            $param = array($xref, $ged_id, $husb, $wife, $chil, $gedrec, $nchi);
            $gBitDb->query("INSERT INTO {$TBLPREFIX}families (f_id, f_file, f_husb, f_wife, f_chil, f_gedcom, f_numchil) VALUES (?,?,?,?,?,?,?)", $param);
            break;
        case 'SOUR':
            if (preg_match('/\\n1 TITL (.+)/', $gedrec, $match)) {
                $name = $match[1];
            } elseif (preg_match('/\\n1 ABBR (.+)/', $gedrec, $match)) {
                $name = $match[1];
            } else {
                $name = $gid;
            }
            if (strpos($gedrec, "\n1 _DBID")) {
                $_dbid = 'Y';
            } else {
                $_dbid = null;
            }
            $gBitDb->query("INSERT INTO {$TBLPREFIX}sources (s_id, s_file, s_name, s_gedcom, s_dbid) VALUES (?,?,?,?,?)", array($xref, $ged_id, $name, $gedrec, $_dbid));
            break;
        case 'OBJE':
            // OBJE records are imported by update_media function
            break;
        case 'HEAD':
            if (!strpos($gedrec, "\n1 DATE ")) {
                $gedrec .= "\n1 DATE " . date('j M Y');
            }
            // no break
        // no break
        default:
            if (substr($type, 0, 1) != '_') {
                $gBitDb->query("INSERT INTO {$TBLPREFIX}other (o_id, o_file, o_type, o_gedcom) VALUES (?,?,?,?)", array($xref, $ged_id, $type, $gedrec));
            }
            break;
    }
    // if this is not an update then write it to the new gedcom file
    if (!$update && !empty($fpnewged)) {
        fwrite($fpnewged, reformat_record_export($gedrec));
    }
    $xtype = $type;
    // Pass value back to uploadgedcom.php
}