示例#1
0
 static function duplicate($id_budget = 0)
 {
     global $dbh;
     $new_bud = new budgets($id_budget);
     $new_bud->id_budget = 0;
     $lib = $new_bud->libelle . '_';
     $l_lib = strlen($lib);
     $q = "select if(max(substring(libelle, " . $l_lib . "+1)) is null, 1, max(substring(libelle, " . $l_lib . "+1))+1)  from budgets ";
     $q .= "where substring(libelle, 1, " . $l_lib . ") = '" . addslashes($lib) . "' ";
     $q .= "and substring(libelle, " . $l_lib . "+1) regexp '^[0-9]+\$' ";
     $r = mysql_query($q, $dbh);
     $n = mysql_result($r, 0, 0);
     $new_bud->libelle = $lib . $n;
     $new_bud->statut = STA_BUD_PRE;
     $new_bud->save();
     $id_new_bud = $new_bud->id_budget;
     $q = budgets::listAllRubriques($id_budget);
     $r = mysql_query($q, $dbh);
     $tab_p = array();
     while ($obj = mysql_fetch_object($r)) {
         $new_rub = new rubriques($obj->id_rubrique);
         $new_rub->num_budget = $id_new_bud;
         $new_rub->id_rubrique = 0;
         if ($obj->num_parent) {
             $new_rub->num_parent = $tab_p[$obj->num_parent];
         }
         $new_rub->save();
         $id_new_rub = $new_rub->id_rubrique;
         $tab_p[$obj->id_rubrique] = $id_new_rub;
     }
     return $id_new_bud;
 }