Skip to content

Commit

Permalink
Merge pull request #99 from fengoffice/releases/3.10.8.21
Browse files Browse the repository at this point in the history
release 3.10.8.21
  • Loading branch information
alvarotm01 committed Mar 21, 2024
2 parents 1b63cb9 + fd55366 commit 32d541a
Show file tree
Hide file tree
Showing 62 changed files with 471 additions and 154 deletions.
23 changes: 15 additions & 8 deletions application/controllers/ContactController.class.php
Expand Up @@ -552,9 +552,8 @@ function list_all()
$join_params['table'] = TABLE_PREFIX . "contact_emails";
$join_params['jt_field'] = "contact_id";
$join_params['e_field'] = "object_id";
//$join_params['on_extra'] = " AND is_main =1";
$join_params['on_extra'] = " AND jt.is_main=1";
$select_columns = array("DISTINCT o.*", "e.*");
//$order = '`email_address`';
$email_order_dir = strtolower($order_dir) == 'desc' ? "1,0" : "0,1";
$order = 'IF(ISNULL(jt.email_address),' . $email_order_dir . '),jt.email_address';
break;
Expand Down Expand Up @@ -594,7 +593,7 @@ function list_all()
'only_count_results' => $only_count_result,
"join_params" => $join_params,
"select_columns" => $select_columns
));
));


// Prepare response object
Expand Down Expand Up @@ -1209,7 +1208,7 @@ function add($data = null, $is_api = false)
$object_controller->add_to_members($contact, $member_ids);
}
$no_perm_members_ids = json_decode(array_var($_POST, 'no_perm_members'));
if (count($no_perm_members_ids)) {
if (isset($no_perm_members_ids) && count($no_perm_members_ids)) {
$object_controller->add_to_members($contact, $no_perm_members_ids);
}
if ($newCompany) {
Expand Down Expand Up @@ -1460,7 +1459,7 @@ function edit()
tpl_assign('user_type', $contact->getUserType());
}

if (is_array($im_types)) {
if (isset($im_types) && is_array($im_types)) {
foreach ($im_types as $im_type) {
$contact_data['im_' . $im_type->getId()] = $contact->getImValue($im_type);
} // foreach
Expand Down Expand Up @@ -1610,7 +1609,7 @@ function edit()
$member_ids_to_add = array_merge($member_ids_to_add, $member_ids);
}
$no_perm_members_ids = json_decode(array_var($_POST, 'no_perm_members'));
if (count($no_perm_members_ids) > 0) {
if (isset($no_perm_members_ids) && count($no_perm_members_ids) > 0) {
$member_ids_to_add = array_merge($member_ids_to_add, $no_perm_members_ids);
}

Expand Down Expand Up @@ -1808,9 +1807,9 @@ function save_non_main_emails($contact_data, $contact)
}
$obj->setEmailTypeId($data['type']);
$obj->setEmailAddress(trim($data['email_address']));
$obj->setIsMain(false);
if(Plugins::instance()->isActivePlugin('income')):
$obj->setIsMain((!isset($data['is_main_email']) ? true : false));
$obj->setDefaultEmail((!isset($data['default_billing_email']) ? true : false));
$obj->setDefaultEmail(isset($data['default_billing_email']) ? true : false);
endif;
$obj->save();
}
Expand Down Expand Up @@ -4455,6 +4454,14 @@ private function getAllowedAddresses($filter)
GROUP BY object_id,email_address
");

/**
* Check if contacts actually exists
* before looping over. Older PHP servers
* (and some modern too) will throw notice
* level errors looping over nulls.
*/
if(!$contacts_addresses) return null;

foreach ($contacts_addresses as $contact) { //first_name surname email_address
/* @var $contact Contact */
$name = str_replace(",", " ", $contact['first_name'] . " " . $contact['surname']);
Expand Down
12 changes: 10 additions & 2 deletions application/controllers/DimensionController.class.php
Expand Up @@ -1083,14 +1083,22 @@ function buildMemberList($all_members, $dimension, $allowed_member_type_ids, $a
function linked_object_filters() {
$genid = gen_id();

$listeners = array('on_selection_change' => "Ext.getCmp('dimFilter').fireEvent('memberselected', member_selector['$genid'].sel_context);");
$listeners = array(
'on_selection_change' => "Ext.getCmp('dimFilter').fireEvent('memberselected', member_selector['$genid'].sel_context);"
);
if (array_var($_REQUEST, 'add_on_remove_function')) {
$listeners['on_remove_relation'] .= "Ext.getCmp('dimFilter').fireEvent('memberselected', member_selector['$genid'].sel_context);";
}

$options = array('select_current_context' => true, 'listeners' => $listeners, 'width' => 300, 'horizontal' => true);

if (array_var($_REQUEST, 'show_associated_dimension_filters')) {
$options['allow_non_manageable'] = true;
$options['dont_exclude_hidden_selectors'] = true;
}
$options['dont_select_associated_members'] = true;
if (array_var($_REQUEST, 'skip_default_member_selections')) {
$options['skip_default_member_selections'] = true;
}

$object_type_id = ProjectMessages::instance()->getObjectTypeId();
if (array_var($_REQUEST, 'object_id')) {
Expand Down
4 changes: 2 additions & 2 deletions application/controllers/EventController.class.php
Expand Up @@ -578,7 +578,7 @@ function delete() {
$ext_user = ExternalCalendarUsers::findByContactId();
if ($ext_user instanceof ExternalCalendarUser) {
$externalCalendarController = new ExternalCalendarController();
$externalCalendarController->delete_event_calendar_extern($event, $ext_user);
$externalCalendarController->delete_event_calendar_extern($event, $ext_user);
}
}
}catch(Exception $e) {
Expand Down Expand Up @@ -1266,7 +1266,7 @@ function icalendar_export_new()

$filename = rand().'.ics';
$handle = fopen(ROOT.'/tmp/'.$filename, 'wb');
fwrite($handle, $buffer);
fwrite($handle, CalFormatUtilities::strip_tags_content($buffer));
fclose($handle);

$_SESSION['calendar_export_filename'] = $filename;
Expand Down
28 changes: 22 additions & 6 deletions application/controllers/MemberController.class.php
Expand Up @@ -121,7 +121,7 @@ function build_listing_order_parameters($order, $order_dir, $member_type) {
$order_join_sql .= " LEFT JOIN ".TABLE_PREFIX."objects ocpv ON ocpv.id=cpv.`value`";
$order = "ocpv.`name`";
} else {
if($cp->getType() == 'numeric'){
if($cp->getType() == 'numeric' || $cp->getType() == 'amount'){
$order = "CAST(cpv.value AS DECIMAL(10,4))";
}else{
$order = "cpv.`value`";
Expand All @@ -140,7 +140,7 @@ function build_listing_order_parameters($order, $order_dir, $member_type) {
$order_join_sql .= " LEFT JOIN ".TABLE_PREFIX."objects ocpv ON ocpv.id=cpv.`value`";
$order = "ocpv.`name`";
} else {
if($cp->getType() == 'numeric'){
if($cp->getType() == 'numeric' || $cp->getType() == 'amount'){
$order = "CAST(cpv.value AS DECIMAL(10,4))";
}else{
$order = "cpv.`value`";
Expand Down Expand Up @@ -2669,6 +2669,7 @@ function get_contacts_of_member(){
ajx_current("empty");

$response = null;
$client_billing_address = null;
$member_ids = explode(',', array_var($_REQUEST, 'customer_id', ''));
$invoice_id = array_var($_REQUEST, 'invoice_id');

Expand All @@ -2679,17 +2680,32 @@ function get_contacts_of_member(){
if (is_null($response)) {
$response = $member_data;
} else {
if (isset($member_data['contacts']['Company']) && count($member_data['contacts']['Company']) > 0) {
// don't override previous key 'Company'
if (!isset($response['contacts']['Company']) && isset($member_data['contacts']['Company']) && count($member_data['contacts']['Company']) > 0) {

$response['contacts']['Company'] = array_merge($response['contacts']['Company'], $member_data['contacts']['Company']);
$client_billing_address=$response['contacts']['Company'][0]['billing_address'];

// set this var only if we have a new value
$ba = $response['contacts']['Company'][0]['billing_address'];
if (isset($ba) && is_array($ba) && count($ba) > 0) {
$client_billing_address = $ba;
}
}

if (isset($member_data['contacts']['Billing Company']) && count($member_data['contacts']['Billing Company']) > 0) {
$response['contacts']['Billing Company'] = array_merge($response['contacts']['Billing Company'], $member_data['contacts']['Billing Company']);
}

if (count($member_data['contacts']) > 0) {

$response['custom_properties'] = array_merge($response['custom_properties'], $member_data['custom_properties']);
$response['contacts'] = array_merge($response['contacts'], $member_data['contacts']);

// don't override previous contacts found with same key
foreach ($member_data['contacts'] as $k => $c) {
if (!isset($response['contacts'][$k])) {
$response['contacts'][$k] = $c;
}
}
}
}
}
Expand All @@ -2698,7 +2714,7 @@ function get_contacts_of_member(){
//$response['contacts']['Company'][0]['client billing address']=$client_billing_address;

//fix patch if billing address is null (not have billing in project), override with CLIENT billing address
if(isset($response['contacts']['Company'][0]['billing_address'][0]['parsed']) && $response['contacts']['Company'][0]['billing_address'][0]['parsed']=='')
if(isset($client_billing_address) && isset($response['contacts']['Company'][0]['billing_address'][0]['parsed']) && $response['contacts']['Company'][0]['billing_address'][0]['parsed']=='')
{
$response['contacts']['Company'][0]['billing_address']=$client_billing_address;
}
Expand Down
24 changes: 18 additions & 6 deletions application/controllers/TaskController.class.php
Expand Up @@ -3118,7 +3118,8 @@ function add_task() {
$parentId = $task->getParentId();
$ico = "ico-task";
$action = "add";
$object = TemplateController::prepareObject($objectId, $id, $objectName, $objectTypeName, $manager, $action, $milestoneId, $subTasks, $parentId, $ico, $task->getObjectTypeId(), $task->isRepetitive());
$template_controller = new TemplateController();
$object = $template_controller->prepareObject($objectId, $id, $objectName, $objectTypeName, $manager, $action, $milestoneId, $subTasks, $parentId, $ico, $task->getObjectTypeId(), $task->isRepetitive());

$template_task_data = array('object' => $object);

Expand Down Expand Up @@ -3683,7 +3684,7 @@ function edit_task() {
$parent->setUseDueTime(array_var($task_data, 'use_due_time', 0));
}
// calculate and set estimated time
$totalMinutes = (array_var($task_data, 'time_estimate_hours') * 60) + (array_var($task_data, 'time_estimate_minutes'));
$totalMinutes = ((int)array_var($task_data, 'time_estimate_hours') * 60) + (int)(array_var($task_data, 'time_estimate_minutes'));
$parent->setTimeEstimate($totalMinutes);
$parent->save();
}
Expand All @@ -3703,6 +3704,13 @@ function edit_task() {
$old_start_date = $task->getStartDate();
$old_due_date = $task->getDueDate();

// Save previous parent task to recalculate total values and percent complete
$recalculate_old_parent = false;
if($task->getParentId() > 0 && $task->getParentId() != $task_data['parent_id']){
$recalculate_old_parent = true;
$old_parent = $task->getParent();
}

if (config_option("wysiwyg_tasks")) {
$task_data['type_content'] = "html";
$task_data['text'] = str_replace(array("\r", "\n", "\r\n"), array('', '', ''), array_var($task_data, 'text'));
Expand All @@ -3712,7 +3720,7 @@ function edit_task() {
$task->setFromAttributes($task_data);


$totalMinutes = (array_var($task_data, 'time_estimate_hours') * 60) + (array_var($task_data, 'time_estimate_minutes'));
$totalMinutes = ((int)array_var($task_data, 'time_estimate_hours') * 60) + (int)(array_var($task_data, 'time_estimate_minutes'));
$task->setTimeEstimate($totalMinutes);

if ($task->getParentId() > 0 && $task->hasChild($task->getParentId())) {
Expand Down Expand Up @@ -3748,10 +3756,14 @@ function edit_task() {
}
}

$task->save();

$task->save();
$task->calculatePercentComplete();

if ($recalculate_old_parent) {
$old_parent->save();
$old_parent->calculatePercentComplete();
}

// dependencies
if (config_option('use tasks dependencies')) {
$previous_tasks = array_var($task_data, 'previous');
Expand Down Expand Up @@ -5349,7 +5361,7 @@ function repetitive_task_related_edit($task, $task_data) {

$task->setFromAttributes($task_data);

$totalMinutes = (array_var($task_data, 'time_estimate_hours') * 60) + (array_var($task_data, 'time_estimate_minutes'));
$totalMinutes = ((int)array_var($task_data, 'time_estimate_hours') * 60) + (int)(array_var($task_data, 'time_estimate_minutes'));
$task->setTimeEstimate($totalMinutes);

if ($task->getParentId() > 0 && $task->hasChild($task->getParentId())) {
Expand Down
24 changes: 19 additions & 5 deletions application/controllers/TemplateController.class.php
Expand Up @@ -112,7 +112,12 @@ function add() {
$cotemplate->setFromAttributes($template_data);
$object_ids = array();
try {
$decoded_prop_inputs = json_decode($_POST['all_prop_inputs'], true);
$all_prop_inputs_json = urldecode(array_var($_POST, 'all_prop_inputs', ''));
$decoded_prop_inputs = json_decode($all_prop_inputs_json, true);

if(json_last_error() != JSON_ERROR_NONE){
throw new Exception(lang('The variable contains an invalid JSON format. Please check the JSON format and try again.'));
}

DB::beginWork();
$cotemplate->save();
Expand Down Expand Up @@ -306,7 +311,7 @@ function add_template_object_to_view($template_id) {
return $objects;
}

function prepareObject($objectId, $id, $objectName, $objectTypeName, $manager, $action,$milestoneId = null , $subTasks = null, $parentId = null, $ico = null, $objectTypeId=0, $is_repetitive=0) {
static function prepareObject($objectId, $id, $objectName, $objectTypeName, $manager, $action,$milestoneId = null , $subTasks = null, $parentId = null, $ico = null, $objectTypeId=0, $is_repetitive=0) {
$object = array(
"object_id" => $objectId,
"object_type_id" => $objectTypeId,
Expand Down Expand Up @@ -348,7 +353,11 @@ private function deleteOldTemporalyTemplateObj(){

function get_prop_input_decoded($decoded_prop_inputs, $prefix) {
$decoded_var = array();


if (!is_array($decoded_prop_inputs)){
return $decoded_var;
}

foreach ($decoded_prop_inputs as $key => $value) {
if (str_starts_with($key, $prefix)) {
preg_match_all("/\[(.*?)\]/", $key, $matches);
Expand All @@ -371,7 +380,7 @@ function get_prop_input_decoded($decoded_prop_inputs, $prefix) {
}
}
}

return $decoded_var;
}

Expand Down Expand Up @@ -416,8 +425,13 @@ function edit() {
} else {
$cotemplate->setFromAttributes($template_data);
try {
$decoded_prop_inputs = json_decode($_POST['all_prop_inputs'], true);
$all_prop_inputs_json = urldecode(array_var($_POST, 'all_prop_inputs', ''));
$decoded_prop_inputs = json_decode($all_prop_inputs_json, true);

if(json_last_error() != JSON_ERROR_NONE){
throw new Exception(lang('The variable contains an invalid JSON format. Please check the JSON format and try again.'));
}

$member_ids = json_decode(array_var($_POST, 'members'));
DB::beginWork();
$tmp_objects = $cotemplate->getObjects();
Expand Down
14 changes: 7 additions & 7 deletions application/controllers/TimeController.class.php
Expand Up @@ -30,14 +30,13 @@ public function index()
//Get Users Info
$users = array();
$context = active_context();
if (!can_manage_time(logged_user())) {
$users = logged_user()->getCompanyId() > 0 ? Contacts::getAllUsers(" AND `company_id` = " . logged_user()->getCompanyId()) : array(logged_user());
} else {
//if (logged_user()->isMemberOfOwnerCompany()) {

if(!SystemPermissions::userHasSystemPermission(logged_user(), 'can_see_others_timeslots')) {
$users = array(logged_user());
} else if (logged_user()->isMemberOfOwnerCompany()) {
$users = Contacts::getAllUsers();
/*} else {
$users = logged_user()->getCompanyId() > 0 ? Contacts::getAllUsers(" AND `company_id` = " . logged_user()->getCompanyId()) : array(logged_user());
}*/
} else {
$users = logged_user()->getCompanyId() > 0 ? Contacts::getAllUsers(" AND `company_id` = " . logged_user()->getCompanyId()) : array(logged_user());
}

// filter users by permissions only if any member is selected.
Expand Down Expand Up @@ -529,6 +528,7 @@ public function add_timeslot($parameters = null, $use_transaction = true)
$task = ProjectTasks::instance()->findById($object_id);
if ($task instanceof ProjectTask) {
$task->calculatePercentComplete();
$task->save();
}

if (!isset($member_ids) || !is_array($member_ids) || count($member_ids) == 0) {
Expand Down
2 changes: 1 addition & 1 deletion application/functions.php
Expand Up @@ -2080,7 +2080,7 @@ function process_uploaded_cropped_picture_file($picture, $crop_data) {

$ext = strtolower(pathinfo($picture['name'], PATHINFO_EXTENSION));
if (in_array($ext, $valid_exts)) {
$path = 'tmp/' . uniqid() . '.' . $ext;
$path = ROOT . '/tmp/' . uniqid() . '.' . $ext;
$size = getimagesize($picture['tmp_name']);

$x = (int) $crop_data['x'];
Expand Down
6 changes: 2 additions & 4 deletions application/helpers/dimension.php
Expand Up @@ -163,15 +163,15 @@ function render_member_selectors($content_object_type_id, $genid = null, $select
$options['filter_by_ids'] = $additional_filters;
}


$selected_members = count($selected_member_ids) > 0 ? Members::instance()->findAll(array('conditions' => 'id IN ('.implode(',', $selected_member_ids).') ')) : array();

foreach($dimensions as $dimension){
$dimension_id = $dimension['dimension_id'];
$dim_sel_mems = array();
foreach ($selected_members as $selected_member) {
if ($selected_member->getDimensionId() == $dimension_id) $dim_sel_mems[] = $selected_member;
}
if (count($dim_sel_mems) == 0 && array_var($options, 'select_current_context')) {
if (count($dim_sel_mems) == 0 && array_var($options, 'select_current_context') && !array_var($options, 'skip_default_member_selections', false)) {
$default_value = DimensionOptions::instance()->getOptionValue($dimension_id, 'default_value');
if ($default_value) {
$default_member = Members::getMemberById($default_value);
Expand All @@ -180,8 +180,6 @@ function render_member_selectors($content_object_type_id, $genid = null, $select
}
}



$skipped_dimensions_cond = "";
if (is_array($skipped_dimensions) && count($skipped_dimensions) > 0) {
$skipped_dimensions_cond = " AND dimension_id NOT IN (".implode(',', $skipped_dimensions).")";
Expand Down
3 changes: 2 additions & 1 deletion application/helpers/format.php
Expand Up @@ -378,7 +378,8 @@ function format_value_to_print($col, $value, $type, $obj_type_id, $textWrapper='
break;
case DATA_TYPE_BOOLEAN:

if(!is_numeric($value) && $value != '') {
if(!is_numeric($value) && $value != '' && $value != '1') {
// if the boolean value is already formatted keep it as it is
$formatted = $value;
}else if ($value == 1){
$formatted = lang('yes');
Expand Down

0 comments on commit 32d541a

Please sign in to comment.