/**
  *   Load all objects with filters
  *
  *   @param		DoliDb	$db				Database handler
  *   @param		int		$socid			Filter by thirdparty
  * 	 @param		int		$fk_element		Id of element action is linked to
  *   @param		string	$elementtype	Type of element action is linked to
  *   @param		string	$filter			Other filter
  *   @param		string	$sortfield		Sort on this field
  *   @param		string	$sortorder		ASC or DESC
  *   @return	array or string			Error string if KO, array with actions if OK
  */
 static function getActions($db, $socid = 0, $fk_element = 0, $elementtype = '', $filter = '', $sortfield = '', $sortorder = '')
 {
     global $conf, $langs;
     $resarray = array();
     $sql = "SELECT a.id";
     $sql .= " FROM " . MAIN_DB_PREFIX . "actioncomm as a";
     $sql .= " WHERE a.entity IN (" . getEntity('actioncomm', 1) . ")";
     if (!empty($socid)) {
         $sql .= " AND a.fk_soc = " . $socid;
     }
     if (!empty($elementtype)) {
         if ($elementtype == 'project') {
             $sql .= ' AND a.fk_project = ' . $fk_element;
         } else {
             $sql .= " AND a.fk_element = " . $fk_element . " AND a.elementtype = '" . $elementtype . "'";
         }
     }
     if (!empty($filter)) {
         $sql .= $filter;
     }
     if ($sortorder && $sortfield) {
         $sql .= $db->order($sortfield, $sortorder);
     }
     dol_syslog(get_class() . "::getActions", LOG_DEBUG);
     $resql = $db->query($sql);
     if ($resql) {
         $num = $db->num_rows($resql);
         if ($num) {
             for ($i = 0; $i < $num; $i++) {
                 $obj = $db->fetch_object($resql);
                 $actioncommstatic = new ActionComm($db);
                 $actioncommstatic->fetch($obj->id);
                 $resarray[$i] = $actioncommstatic;
             }
         }
         $db->free($resql);
         return $resarray;
     } else {
         return $db->lasterror();
     }
 }