/**
  * Smazaže kontakt i jeho subkontakty
  *
  * @return boolean
  */
 public function rename($newname)
 {
     $oldname = $this->getName();
     $this->setDataValue($this->nameColumn, $newname);
     if ($this->saveToMySQL()) {
         $childs = $this->getChilds();
         $subcontact = new IEContact();
         $service = new IEService();
         foreach ($childs as $childID => $childInfo) {
             $subcontact->loadFromMySQL($childID);
             $type = $subcontact->getDataValue('alias');
             $subcontact->setDataValue($subcontact->nameColumn, $newname . ' ' . $type);
             $services = $this->myDbLink->queryTo2DArray('SELECT ' . $service->getmyKeyColumn() . ' FROM ' . $service->myTable . ' WHERE contacts LIKE \'%' . $oldname . ' ' . $type . '%\'');
             if (count($services)) {
                 foreach ($services as $serviceID) {
                     $service->loadFromMySQL((int) $serviceID);
                     if ($service->delMember('contacts', $id)) {
                         $service->addMember('contacts', $id, $newname . ' ' . $type);
                         $service->saveToMySQL();
                     }
                 }
             }
             $subcontact->saveToMySQL();
         }
     } else {
         $this->addStatusMessage(_('Kontakt nelze přejmenovat'), 'warning');
     }
 }
 /**
  * Uloží položky
  *
  * @param array $request
  */
 public static function saveMembers($request)
 {
     $service = new IEService();
     if (isset($request[$service->myKeyColumn])) {
         if ($service->loadFromMySQL((int) $request[$service->myKeyColumn])) {
             if (isset($request['addservice']) || isset($request['delservice'])) {
                 if (isset($request['addservice'])) {
                     $service->addMember('host_name', $request['host_id'], $request['host_name']);
                     if ($service->saveToMySQL()) {
                         $service->addStatusMessage(sprintf(_('položka %s byla přidána'), $request['addservice']), 'success');
                         if ($service->getDataValue('autocfg') == '1') {
                             $service->addStatusMessage(sprintf(_('Službu %s je nutné nejprve zkonfigurovat'), $request['addservice']), 'warning');
                             EaseShared::webPage()->redirect('servicetweak.php?host_id=' . $request['host_id'] . '&service_id=' . $request[$service->myKeyColumn]);
                             exit;
                         }
                     } else {
                         $service->addStatusMessage(sprintf(_('položka %s nebyla přidána'), $request['addservice']), 'warning');
                     }
                 }
                 if (isset($request['delservice'])) {
                     $service->delMember('host_name', $request['host_id'], $request['host_name']);
                     if ($service->saveToMySQL()) {
                         $service->addStatusMessage(sprintf(_('položka %s byla odebrána'), $request['delservice']), 'success');
                     } else {
                         $service->addStatusMessage(sprintf(_('položka %s nebyla odebrána'), $request['delservice']), 'warning');
                     }
                 }
             }
         }
     }
 }
$delete = $oPage->getGetValue('delete', 'bool');
if ($delete == 'true') {
    $service->delete();
    $oPage->redirect('host.php?host_id=' . $host->getId());
    exit;
}
if ($service->getOwnerID() != $oUser->getMyKey()) {
    if ($service->fork($host)) {
        $oUser->addStatusMessage(_('Služba jiného vlastníka byla odvozena jako vlastní'), 'success');
    } else {
        $oUser->addStatusMessage(_('Služba nebyla odvozena'), 'error');
    }
}
$delhost = $oPage->getGetValue('delhost');
if ($delhost) {
    $service->delMember('host_name', $oPage->getGetValue('host_id', 'int'), $delhost);
    $service->saveToMySql();
}
$addhost = $oPage->getGetValue('addhost');
if ($addhost) {
    $service->addMember('host_name', $oPage->getGetValue('host_id', 'int'), $addhost);
    $service->saveToMySql();
}
$delcnt = $oPage->getGetValue('delcontact');
if ($delcnt) {
    $service->delMember('contacts', $oPage->getGetValue('contact_id', 'int'), $delcnt);
    $service->saveToMySql();
}
$addcnt = $oPage->getGetValue('addcontact');
if ($addcnt) {
    $service->addMember('contacts', $oPage->getGetValue('contact_id', 'int'), $addcnt);
 function fixContactIDs()
 {
     $contactsOK = array();
     $contactsErr = array();
     $contact = new IEContact();
     $service = new IEService();
     $services = $service->getColumnsFromMySQL(array($service->myKeyColumn));
     foreach ($services as $serviceId => $serviceInfo) {
         $serviceId = intval(current($serviceInfo));
         $service->loadFromMySQL($serviceId);
         $contactNames = $service->getDataValue('contacts');
         if ($contactNames) {
             foreach ($contactNames as $contactId => $contactName) {
                 $contactFound = $contact->loadFromMySQL($contactName);
                 if ($contactId != $contact->getId()) {
                     if ($service->delMember('contacts', $contactId, $contactName) && $service->addMember('contacts', $contact->getId(), $contactName)) {
                         $contactsOK[] = $contactName;
                     } else {
                         $contactsErr[] = $contactName;
                     }
                 }
             }
         }
         if (count($contactsOK)) {
             if ($service->saveToMySQL()) {
                 $this->addItemSmart(sprintf(_('<strong>%s</strong> : %s'), $service->getName(), implode(',', $contactsOK)), array('class' => 'list-group-item'));
                 $this->addStatusMessage(sprintf(_('%s : %s'), $service->getName(), implode(',', $contactsOK)), 'success');
                 $contactsOK = array();
             }
         }
     }
     $host = new IEHost();
     $hosts = $host->getColumnsFromMySQL(array($host->myKeyColumn));
     foreach ($hosts as $hostInfo) {
         $hostId = intval(current($hostInfo));
         $host->loadFromMySQL($hostId);
         $contactNames = $host->getDataValue('contacts');
         if ($contactNames) {
             foreach ($contactNames as $contactId => $contactName) {
                 $contactFound = $contact->loadFromMySQL($contactName);
                 if ($contactId != $contact->getId()) {
                     if ($host->delMember('contacts', $contactId, $contactName) && $host->addMember('contacts', $contact->getId(), $contactName)) {
                         $contactsOK[] = $contactName;
                     } else {
                         $contactsErr[] = $contactName;
                     }
                 }
             }
         }
         if (count($contactsOK)) {
             if ($host->saveToMySQL()) {
                 $this->addItemSmart(sprintf(_('<strong>%s</strong> : %s'), $host->getName(), implode(',', $contactsOK)), array('class' => 'list-group-item'));
                 $this->addStatusMessage(sprintf(_('%s : %s'), $host->getName(), implode(',', $contactsOK)), 'success');
                 $contactsOK = array();
             }
         }
     }
 }