当前位置: 首页>>代码示例>>PHP>>正文


PHP DoliDB::begin方法代码示例

本文整理汇总了PHP中DoliDB::begin方法的典型用法代码示例。如果您正苦于以下问题:PHP DoliDB::begin方法的具体用法?PHP DoliDB::begin怎么用?PHP DoliDB::begin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DoliDB的用法示例。


在下文中一共展示了DoliDB::begin方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: dol_set_user_param

/**
 *	Save personnal parameter
 *
 *	@param	DoliDB	$db         Handler database
 *	@param	Conf	$conf		Object conf
 *	@param	User	&$user      Object user
 *	@param	array	$tab        Tableau (cle=>valeur) des parametres a sauvegarder
 *	@return int         		<0 if KO, >0 if OK
 *
 *	@see		dolibarr_get_const, dolibarr_set_const, dolibarr_del_const
 */
function dol_set_user_param($db, $conf, &$user, $tab)
{
    // Verification parametres
    if (count($tab) < 1) {
        return -1;
    }
    $db->begin();
    // We remove old parameters for all keys in $tab
    $sql = "DELETE FROM " . MAIN_DB_PREFIX . "user_param";
    $sql .= " WHERE fk_user = " . $user->id;
    $sql .= " AND entity = " . $conf->entity;
    $sql .= " AND param in (";
    $i = 0;
    foreach ($tab as $key => $value) {
        if ($i > 0) {
            $sql .= ',';
        }
        $sql .= "'" . $key . "'";
        $i++;
    }
    $sql .= ")";
    dol_syslog("functions2.lib::dol_set_user_param sql=" . $sql, LOG_DEBUG);
    $resql = $db->query($sql);
    if (!$resql) {
        dol_print_error($db);
        $db->rollback();
        return -1;
    }
    foreach ($tab as $key => $value) {
        // Set new parameters
        if ($value) {
            $sql = "INSERT INTO " . MAIN_DB_PREFIX . "user_param(fk_user,entity,param,value)";
            $sql .= " VALUES (" . $user->id . "," . $conf->entity . ",";
            $sql .= " '" . $key . "','" . $db->escape($value) . "');";
            dol_syslog("functions2.lib::dol_set_user_param sql=" . $sql, LOG_DEBUG);
            $result = $db->query($sql);
            if (!$result) {
                dol_print_error($db);
                $db->rollback();
                return -1;
            }
            $user->conf->{$key} = $value;
            //print "key=".$key." user->conf->key=".$user->conf->$key;
        } else {
            unset($user->conf->{$key});
        }
    }
    $db->commit();
    return 1;
}
开发者ID:nrjacker4,项目名称:crm-php,代码行数:61,代码来源:functions2.lib.php

示例2: saveboxorder

 /**
  *  Save order of boxes for area and user
  *
  *  @param	DoliDB	$db				Database handler
  *  @param	string	$zone       	Name of area (0 for Homepage, ...)
  *  @param  string  $boxorder   	List of boxes with correct order 'A:123,456,...-B:789,321...'
  *  @param  int     $userid     	Id of user
  *  @return int                   	<0 if KO, >= 0 if OK
  */
 static function saveboxorder($db, $zone, $boxorder, $userid = 0)
 {
     global $conf;
     $error = 0;
     require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
     dol_syslog(get_class() . "::saveboxorder zone=" . $zone . " userid=" . $userid);
     if (!$userid || $userid == 0) {
         return 0;
     }
     $user = new User($db);
     $user->id = $userid;
     $db->begin();
     // Save parameters to say user has a dedicated setup
     $tab = array();
     $confuserzone = 'MAIN_BOXES_' . $zone;
     $tab[$confuserzone] = 1;
     if (dol_set_user_param($db, $conf, $user, $tab) < 0) {
         $error = $db->lasterror();
         $db->rollback();
         return -3;
     }
     // Delete all lines
     $sql = "DELETE FROM " . MAIN_DB_PREFIX . "boxes";
     $sql .= " WHERE entity = " . $conf->entity;
     $sql .= " AND fk_user = " . $userid;
     $sql .= " AND position = " . $zone;
     dol_syslog(get_class() . "::saveboxorder", LOG_DEBUG);
     $result = $db->query($sql);
     if ($result) {
         $colonnes = explode('-', $boxorder);
         foreach ($colonnes as $collist) {
             $part = explode(':', $collist);
             $colonne = $part[0];
             $list = $part[1];
             dol_syslog(get_class() . "::saveboxorder column=" . $colonne . ' list=' . $list);
             $i = 0;
             $listarray = explode(',', $list);
             foreach ($listarray as $id) {
                 if (is_numeric($id)) {
                     //dol_syslog("aaaaa".count($listarray));
                     $i++;
                     $ii = sprintf('%02d', $i);
                     $sql = "INSERT INTO " . MAIN_DB_PREFIX . "boxes";
                     $sql .= "(box_id, position, box_order, fk_user, entity)";
                     $sql .= " values (";
                     $sql .= " " . $id . ",";
                     $sql .= " " . $zone . ",";
                     $sql .= " '" . $colonne . $ii . "',";
                     $sql .= " " . $userid . ",";
                     $sql .= " " . $conf->entity;
                     $sql .= ")";
                     dol_syslog(get_class() . "::saveboxorder", LOG_DEBUG);
                     $result = $db->query($sql);
                     if ($result < 0) {
                         $error++;
                         break;
                     }
                 }
             }
         }
         if ($error) {
             $error = $db->error();
             $db->rollback();
             return -2;
         } else {
             $db->commit();
             return 1;
         }
     } else {
         $error = $db->lasterror();
         $db->rollback();
         dol_syslog(get_class() . "::saveboxorder " . $error);
         return -1;
     }
 }
开发者ID:Samara94,项目名称:dolibarr,代码行数:84,代码来源:infobox.class.php

示例3: doActions

 /**
  *  Load data control
  *
  *  @param	string	$action    Type of action
  *  @param	int		$id			Id of object
  *	@return	void
  */
 function doActions(&$action, $id)
 {
     global $conf, $user, $langs;
     // Creation utilisateur depuis Adherent
     if ($action == 'confirm_create_user' && GETPOST("confirm") == 'yes') {
         // Recuperation adherent actuel
         $result = $this->object->fetch($id);
         if ($result > 0) {
             $this->db->begin();
             // Creation user
             $nuser = new User($this->db);
             $result = $nuser->create_from_member($this->object, $_POST["login"]);
             if ($result > 0) {
                 $result2 = $nuser->setPassword($user, $_POST["password"], 0, 1, 1);
                 if ($result2) {
                     $this->db->commit();
                 } else {
                     $this->db->rollback();
                 }
             } else {
                 $this->errors[] = $nuser->error;
                 $this->db->rollback();
             }
         } else {
             $this->errors = $this->object->errors;
         }
     }
     // Creation adherent
     if ($action == 'add') {
         $this->assign_post();
         if (!$_POST["name"]) {
             array_push($this->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("Lastname") . ' / ' . $langs->transnoentities("Label")));
             $action = 'create';
         }
         if ($_POST["name"]) {
             $id = $this->object->create($user);
             if ($id > 0) {
                 header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
                 exit;
             } else {
                 $this->errors = $this->object->errors;
                 $action = 'create';
             }
         }
     }
     if ($action == 'confirm_delete' && GETPOST("confirm") == 'yes') {
         $result = $this->object->fetch($id);
         $this->object->old_name = $_POST["old_name"];
         $this->object->old_firstname = $_POST["old_firstname"];
         $result = $this->object->delete();
         if ($result > 0) {
             header("Location: list.php");
             exit;
         } else {
             $this->errors = $this->object->errors;
         }
     }
     if ($action == 'update') {
         if ($_POST["cancel"]) {
             header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $this->object->id);
             exit;
         }
         if (empty($_POST["name"])) {
             $this->error = array($langs->trans("ErrorFieldRequired", $langs->transnoentities("Name") . ' / ' . $langs->transnoentities("Label")));
             $action = 'edit';
         }
         if (empty($this->error)) {
             $this->object->fetch($_POST["adherentid"]);
             $this->object->oldcopy = clone $this->object;
             $this->assign_post();
             $result = $this->object->update($_POST["adherentid"], $user);
             if ($result > 0) {
                 header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $this->object->id);
                 exit;
             } else {
                 $this->errors = $this->object->errors;
                 $action = 'edit';
             }
         }
     }
 }
开发者ID:Samara94,项目名称:dolibarr,代码行数:88,代码来源:actions_adherentcard_common.class.php

示例4: migrate_event_assignement

/**
 * Migrate event assignement to owner
 *
 * @param	DoliDB		$db				Database handler
 * @param	Translate	$langs			Object langs
 * @param	Conf		$conf			Object conf
 * @return	void
 */
function migrate_event_assignement($db, $langs, $conf)
{
    print '<tr><td colspan="4">';
    print '<br>';
    print '<b>' . $langs->trans('MigrationEvents') . "</b><br>\n";
    $error = 0;
    dolibarr_install_syslog("upgrade2::migrate_event_assignement");
    $db->begin();
    $sqlSelect = "SELECT a.id, a.fk_user_action";
    $sqlSelect .= " FROM " . MAIN_DB_PREFIX . "actioncomm as a";
    $sqlSelect .= " LEFT JOIN " . MAIN_DB_PREFIX . "actioncomm_resources as ar ON ar.fk_actioncomm = a.id AND ar.element_type = 'user' AND ar.fk_element = a.fk_user_action";
    $sqlSelect .= " WHERE fk_user_action > 0 AND fk_user_action NOT IN (SELECT fk_element FROM " . MAIN_DB_PREFIX . "actioncomm_resources as ar WHERE ar.fk_actioncomm = a.id AND ar.element_type = 'user')";
    $sqlSelect .= " ORDER BY a.id";
    //print $sqlSelect;
    $resql = $db->query($sqlSelect);
    if ($resql) {
        $i = 0;
        $num = $db->num_rows($resql);
        if ($num) {
            while ($i < $num) {
                $obj = $db->fetch_object($resql);
                $sqlUpdate = "INSERT INTO " . MAIN_DB_PREFIX . "actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
                $sqlUpdate .= "VALUES(" . $obj->id . ", 'user', " . $obj->fk_user_action . ")";
                $result = $db->query($sqlUpdate);
                if (!$result) {
                    $error++;
                    dol_print_error($db);
                }
                print ". ";
                $i++;
            }
        } else {
            print $langs->trans('AlreadyDone') . "<br>\n";
        }
        if (!$error) {
            $db->commit();
        } else {
            $db->rollback();
        }
    } else {
        dol_print_error($db);
        $db->rollback();
    }
    print '</td></tr>';
}
开发者ID:ADDAdev,项目名称:Dolibarr,代码行数:53,代码来源:upgrade2.php

示例5: migrate_mode_reglement

/**
 * Migrate link stored into fk_mode_reglement
 *
 * @param	DoliDB		$db		Database handler
 * @param	Translate	$langs	Object langs
 * @param	Conf		$conf	Object conf
 * @return	void
 */
function migrate_mode_reglement($db,$langs,$conf)
{
	print '<tr><td colspan="4">';

	print '<br>';
	print '<b>'.$langs->trans('MigrationPaymentMode')."</b><br>\n";

	$elements = array(
		'old_id' => array(5,8,9,10,11),
		'new_id' => array(50,51,52,53,54),
		'code' => array('VAD','TRA','LCR','FAC','PRO'),
		'tables' => array('commande_fournisseur','commande','facture_rec','facture','propal')
	);
	$count=0;

	foreach($elements['old_id'] as $key => $old_id)
	{
		$error=0;

		dolibarr_install_syslog("upgrade2::migrate_mode_reglement code=".$elements['code'][$key]);

		$sqlSelect = "SELECT id";
		$sqlSelect.= " FROM ".MAIN_DB_PREFIX."c_paiement";
		$sqlSelect.= " WHERE id = ".$old_id;
		$sqlSelect.= " AND code = '".$elements['code'][$key]."'";

		$resql = $db->query($sqlSelect);
		if ($resql)
		{
			$num = $db->num_rows($resql);
			if ($num)
			{
				$count++;

				$db->begin();

				$sql = "UPDATE ".MAIN_DB_PREFIX."c_paiement SET ";
				$sql.= "id = ".$elements['new_id'][$key];
				$sql.= " WHERE id = ".$old_id;
				$sql.= " AND code = '".$elements['code'][$key]."'";

				$resql = $db->query($sql);
				if ($resql)
				{
					foreach($elements['tables'] as $table)
					{
						$sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET ";
						$sql.= "fk_mode_reglement = ".$elements['new_id'][$key];
						$sql.= " WHERE fk_mode_reglement = ".$old_id;

						$resql = $db->query($sql);
						if (! $resql)
						{
							dol_print_error($db);
							$error++;
						}
						print ". ";
					}

					if (! $error)
					{
						$db->commit();
					}
					else
					{
						dol_print_error($db);
						$db->rollback();
					}
				}
				else
				{
					dol_print_error($db);
					$db->rollback();
				}
			}
		}
	}

	if ($count == 0) print $langs->trans('AlreadyDone')."<br>\n";


	print '</td></tr>';
}
开发者ID:nrjacker4,项目名称:crm-php,代码行数:91,代码来源:upgrade2.php

示例6: migrate_categorie_association

/**
 * Migrate categorie association
 *
 * @param	DoliDB		$db				Database handler
 * @param	Translate	$langs			Object langs
 * @param	Conf		$conf			Object conf
 * @return	void
 */
function migrate_categorie_association($db, $langs, $conf)
{
    print '<tr><td colspan="4">';
    print '<br>';
    print '<b>' . $langs->trans('MigrationCategorieAssociation') . "</b><br>\n";
    $error = 0;
    if ($db->DDLInfoTable(MAIN_DB_PREFIX . "categorie_association")) {
        dolibarr_install_syslog("upgrade2::migrate_categorie_association");
        $db->begin();
        $sqlSelect = "SELECT fk_categorie_mere, fk_categorie_fille";
        $sqlSelect .= " FROM " . MAIN_DB_PREFIX . "categorie_association";
        $resql = $db->query($sqlSelect);
        if ($resql) {
            $i = 0;
            $num = $db->num_rows($resql);
            if ($num) {
                while ($i < $num) {
                    $obj = $db->fetch_object($resql);
                    $sqlUpdate = "UPDATE " . MAIN_DB_PREFIX . "categorie SET ";
                    $sqlUpdate .= "fk_parent = " . $obj->fk_categorie_mere;
                    $sqlUpdate .= " WHERE rowid = " . $obj->fk_categorie_fille;
                    $result = $db->query($sqlUpdate);
                    if (!$result) {
                        $error++;
                        dol_print_error($db);
                    }
                    print ". ";
                    $i++;
                }
            } else {
                print $langs->trans('AlreadyDone') . "<br>\n";
            }
            if (!$error) {
                // TODO DROP table in the next release
                /*
                $sqlDrop = "DROP TABLE ".MAIN_DB_PREFIX."categorie_association";
                if ($db->query($sqlDrop))
                {
                	$db->commit();
                }
                else
                {
                	$db->rollback();
                }
                */
                $db->commit();
            } else {
                $db->rollback();
            }
        } else {
            dol_print_error($db);
            $db->rollback();
        }
    } else {
        print $langs->trans('AlreadyDone') . "<br>\n";
    }
    print '</td></tr>';
}
开发者ID:LionSystemsSolutions,项目名称:El-Canelo-ERP,代码行数:66,代码来源:upgrade2.php


注:本文中的DoliDB::begin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。