67 create table docenum (
75 create index if_docenum on docenum(famid, attrid);
76 create unique index i_docenum on docenum(famid, attrid, key);
81 if ($this->needChangeOrder) {
88 if ($this->needChangeOrder) {
108 if (empty($this->eorder) || $this->eorder < 0) {
109 $sql = sprintf(
"select max(eorder) from docenum where famid = '%s' and attrid='%s'", pg_escape_string($this->famid) , pg_escape_string($this->attrid));
112 $this->eorder = intval($newOrder) + 1;
120 $sql = sprintf(
"update docenum set eorder=eorder + 1 where famid = '%s' and attrid='%s' and key != '%s' and eorder >= %d", pg_escape_string($this->famid) , pg_escape_string($this->attrid) , pg_escape_string($this->key) , $n);
122 $seqName = uniqid(
"tmpseqenum");
123 $sql = sprintf(
"create temporary sequence %s;", $seqName);
125 $sql.= sprintf(
"UPDATE docenum SET eorder = neworder from (SELECT *, nextval('%s') as neworder from (select * from docenum where famid='%s' and attrid = '%s' order by eorder) as tmpz) as w where w.famid=docenum.famid and w.attrid=docenum.attrid and docenum.key=w.key;", $seqName, pg_escape_string($this->famid) , pg_escape_string($this->attrid));
132 if ($this->famid && $this->attrid && $this->key !== null) {
133 simpleQuery($this->dbaccess, sprintf(
"select true from docenum where famid=%d and attrid='%s' and key='%s'", ($this->famid) , pg_escape_string($this->attrid) , pg_escape_string($this->key)) ,
$r,
true,
true);
141 if (!is_numeric(
$famId)) {
145 $sql = sprintf(
"select * from docenum where famid=%d and attrid='%s' order by eorder",
$famId, pg_escape_string(
$attrid));
151 if (!is_numeric(
$famId)) {
155 $sql = sprintf(
"select key from docenum where famid=%d and attrid='%s' and disabled",
$famId, pg_escape_string(
$attrid));
163 $sql = sprintf(
"SELECT count(*) FROM docenum WHERE famid = %d AND attrid = '%s'", $this->famid, pg_escape_string($this->attrid));
165 if ($beforeThan !== null) {
166 $sql = sprintf(
"select eorder from docenum where famid=%d and attrid='%s' and key='%s'", $this->famid, pg_escape_string($this->attrid) , pg_escape_string($beforeThan));
169 $this->eorder = $beforeOrder;
172 $this->eorder = $count + 1;
174 }
else if (empty($this->eorder)) {
179 $this->eorder = $count + 1;
184 if (!is_numeric(
$famId)) {
193 if ($enum->isAffected()) {
194 throw new \Dcp\Exception(sprintf(
"Enum %s#%s#%s already exists",
$famId,
$attrid, $enumStruct->key));
199 $enum->key = $enumStruct->key;
200 $enum->label = $enumStruct->label;
201 $enum->disabled = ($enumStruct->disabled ===
true);
202 $enum->needChangeOrder =
true;
203 $enum->eorder = $enumStruct->absoluteOrder;
204 if ($enumStruct->orderBeforeThan === null) {
205 $enum->setOrder(null);
207 $enum->setOrder($enumStruct->orderBeforeThan);
211 throw new \Dcp\Exception(sprintf(
"Cannot add enum %s#%s#%s : %s",
$famId,
$attrid, $enumStruct->key,
$err));
214 if ($enumStruct->localeLabel) {
215 foreach ($enumStruct->localeLabel as $lLabel) {
216 self::changeLocale(
$famId,
$attrid, $enumStruct->key, $lLabel->lang, $lLabel->label);
223 if (!is_numeric(
$famId)) {
232 if (!$enum->isAffected()) {
233 throw new \Dcp\Exception(sprintf(
"Enum %s#%s#%s not found",
$famId,
$attrid, $enumStruct->key));
236 $enum->label = $enumStruct->label;
237 $enum->disabled = ($enumStruct->disabled ===
true);
238 if ($enum->eorder != $enumStruct->absoluteOrder) {
239 $enum->needChangeOrder =
true;
240 $enum->eorder = $enumStruct->absoluteOrder;
242 if ($enumStruct->orderBeforeThan) {
243 $enum->setOrder($enumStruct->orderBeforeThan);
246 $err = $enum->modify();
248 throw new \Dcp\Exception(sprintf(
"Cannot modify enum %s#%s#%s : %s",
$famId,
$attrid, $enumStruct->key,
$err));
250 if ($enumStruct->localeLabel) {
251 foreach ($enumStruct->localeLabel as $lLabel) {
252 self::changeLocale(
$famId,
$attrid, $enumStruct->key, $lLabel->lang, $lLabel->label);
261 $moFile = sprintf(
"%s/locale/%s/LC_MESSAGES/customFamily_%s.mo",
DEFAULT_PUBDIR, substr(
$lang, 0, 2) , $fam->name);
276 $oa = $fam->getAttribute(
$attrid);
278 throw new \Dcp\Exception(sprintf(
"Locale : Enum %s#%s#%s not found",
$famId,
$attrid, $enumId));
287 $moFile = self::getMoFilename($fam->name,
$lang);
288 $poFile = sprintf(
"%s.po", (substr($moFile, 0, -3)));
290 $msgInit = sprintf(
'msgid ""
292 "Project-Id-Version: Custom enum for %s\n"
294 "PO-Revision-Date: %s"
295 "MIME-Version: 1.0\n"
296 "Content-Type: text/plain; charset=UTF-8\n"
297 "Content-Transfer-Encoding: 8bit\n"', $fam->name, substr(
$lang, 0, 2) , date(
'Y-m-d H:i:s'));
298 if (file_exists($moFile)) {
300 $cmd = sprintf(
"(msgunfmt %s > %s) 2>&1", escapeshellarg($moFile) , escapeshellarg($poFile));
304 throw new \Dcp\Exception(sprintf(
"Locale : Enum %s#%s#%s error : %s",
$famId,
$attrid, $enumId, implode(
',', $output)));
307 file_put_contents($poFile, $msgInit);
310 $localeKey = sprintf(
"%s#%s#%s", $fam->name, $oa->id, $enumId);
311 $msgEntry = sprintf(
'msgid "%s"' .
"\n" .
'msgstr "%s"', str_replace(
'"',
'\\"', $localeKey) , str_replace(
'"',
'\\"',
$label));
312 $content = file_get_contents($poFile);
314 $match = sprintf(
'msgid "%s"', $localeKey);
315 $content = str_replace($match,
"#, fuzzy\n$match", $content);
317 $content = str_replace(
'msgid ""',
"#, fuzzy\nmsgid \"- HEADER DELETION -\"", $content);
319 file_put_contents($poFile, $msgInit . $msgEntry .
"\n\n" . $content);
320 $cmd = sprintf(
"(msguniq --use-first %s | msgfmt - -o %s; rm -f %s) 2>&1", escapeshellarg($poFile) , escapeshellarg($moFile) , escapeshellarg($poFile));
324 throw new \Dcp\Exception(sprintf(
"Locale : Enum %s#%s#%s error : %s",
$famId,
$attrid, $enumId, implode(
',', $output)));
355 $this->disabled =
false;
356 $this->relativeOrder = null;
357 $this->orderBeforeThan = null;
358 $this->localeLabel = array();
359 foreach ($o as $k => $v) {
360 if ($k !=
"localeLabel") {
364 $this->localeLabel[] =
new EnumLocale($locale[
"lang"], $locale[
"label"]);
static modifyEnum($famId, $attrid, EnumStructure $enumStruct)
static addEnum($famId, $attrid, EnumStructure $enumStruct)
static getDisabledKeys($famId, $attrid)
foreach($argv as $arg) $cmd
__construct($lang, $label)
getFamIdFromName($dbaccess, $name)
new_Doc($dbaccess, $id= '', $latest=false)
static getFamilyEnums($famId, $attrid)
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
if($file) if($subject==""&&$file) if($subject=="") $err
static changeLocale($famId, $attrid, $enumId, $lang, $label)
static getMoFilename($famId, $lang)