}
}
}
-*/
+*/
+
+ if (!($ret = db_query("SELECT MAX(`order_no`) FROM `{$pref}sales_orders`")) ||
+ !db_num_rows($ret))
+ {
+ display_error(_('Cannot query max sales order number.'));
+ return false;
+ }
+ $row = db_fetch($ret);
+ $max_order = $row[0];
+ $next_ref = $max_order+1;
+ $sql = "UPDATE `{$pref}sys_types`
+ SET `type_no`='$max_order',
+ `next_reference`='$next_ref'
+ WHERE `type_id`=30";
+ if(!db_query($sql))
+ {
+ display_error(_('Cannot store next sales order reference.'));
+ return false;
+ }
+
return convert_roles($pref);
}
//
// Test if patch was applied before.
//
function installed($pref) {
- if (check_table($pref, 'company', 'login_tout')) return false;
- if (check_table($pref, 'stock_category', 'dflt_dim2')) return false;
- if (check_table($pref, 'users', 'sticky_doc_date')) return false;
- if (check_table($pref, 'audit_trail')) return false;
- if (check_table($pref, 'stock_master','no_sale')) return false;
- if (check_table($pref, 'users', 'role_id')) return false;
- return true;
+ $n = 14; // number of features to be installed
+ if (check_table($pref, 'company', 'custom1_name')) $n--;
+ if (!check_table($pref, 'company', 'profit_loss_year_act')) $n--;
+ if (!check_table($pref, 'company', 'login_tout')) $n--;
+ if (!check_table($pref, 'stock_category', 'dflt_no_sale')) $n--;
+ if (!check_table($pref, 'users', 'sticky_doc_date')) $n--;
+ if (!check_table($pref, 'users', 'startup_tab')) $n--;
+ if (!check_table($pref, 'cust_branch', 'inactive')) $n--;
+ if (!check_table($pref, 'chart_class', 'ctype')) $n--;
+ if (!check_table($pref, 'audit_trail')) $n--;
+ if (!check_table($pref, 'currencies', 'auto_update')) $n--;
+ if (!check_table($pref, 'stock_master','no_sale')) $n--;
+ if (!check_table($pref, 'suppliers', 'supp_ref')) $n--;
+ if (!check_table($pref, 'users', 'role_id')) $n--;
+ if (!check_table($pref, 'sales_orders', 'reference')) $n--;
+ return $n == 0 ? true : 14 - $n;
}
};
20 => array('SA_CREATECOMPANY', 'SA_CREATELANGUAGE', 'SA_CREATEMODULES',
'SA_SOFTWAREUPGRADE', 'SA_SECROLES')
);
-
+ $new_ids = array();
foreach ($security_groups as $role_id => $areas) {
$area_set = array();
$sections = array();
foreach ($areas as $a) {
if (isset($trans_sec[$a]))
foreach ($trans_sec[$a] as $id) {
- if ($security_areas[$id][0]==0)
+ if ($security_areas[$id][0] != 0)
// error_log('invalid area id: '.$a.':'.$id);
$area_set[] = $security_areas[$id][0];
$sections[$security_areas[$id][0]&~0xff] = 1;
$sections = array_keys($sections);
sort($sections); sort($area_set);
import_security_role($pref, $security_headings[$role_id], $sections, $area_set);
- $new = db_insert_id();
- $sql = "UPDATE {$pref}users set role_id=$new WHERE role_id=$role_id";
- $ret = db_query($sql, 'cannot update users roles');
- if(!$ret) return false;
+ $new_ids[$role_id] = db_insert_id();
+ }
+ $result = get_users(true);
+ $users = array();
+ while($row = db_fetch($result)) { // complete old user ids and roles
+ $users[$row['role_id']][] = $row['id'];
}
+ foreach($users as $old_id => $uids)
+ foreach( $uids as $id) {
+ $sql = "UPDATE {$pref}users set role_id=".$new_ids[$old_id].
+ " WHERE id=$id";
+ $ret = db_query($sql, 'cannot update users roles');
+ if(!$ret) return false;
+ }
return true;
}