diff --git a/main/inc/ajax/skill.ajax.php b/main/inc/ajax/skill.ajax.php index 264a579148..3b59198361 100755 --- a/main/inc/ajax/skill.ajax.php +++ b/main/inc/ajax/skill.ajax.php @@ -136,6 +136,16 @@ switch ($action) { $all = $skill->get_skills_tree_json($user_id, $skill_id, false, $depth); echo $all; break; + case 'get_user_skill': + $userId = api_get_user_id(); + $skillId = isset($_REQUEST['profile_id']) ? $_REQUEST['profile_id'] : 0; + $skill = $skill->user_has_skill($userId, $skillId); + if ($skill) { + echo 1; + } else { + echo 0; + } + break; case 'get_user_skills': $skills = $skill->get_user_skills($user_id, true); Display::display_no_header(); @@ -273,13 +283,24 @@ switch ($action) { } } break; + case 'get_profile': + $skillRelProfile = new SkillRelProfile(); + $profileId = isset($_REQUEST['profile_id']) ? $_REQUEST['profile_id'] : null; + $profile = $skillRelProfile->getProfileInfo($profileId); + echo json_encode($profile); + break; case 'save_profile': if (api_is_platform_admin() || api_is_drh()) { $skill_profile = new SkillProfile(); $params = $_REQUEST; //$params['skills'] = isset($_SESSION['skills']) ? $_SESSION['skills'] : null; $params['skills'] = $params['skill_id']; - $skill_data = $skill_profile->save($params); + $profileId = isset($_REQUEST['profile']) ? $_REQUEST['profile'] : null; + if ($profileId > 0) { + $skill_data = $skill_profile->UpdateProfileInfo($profileId,$params['name'],$params['description']); + } else { + $skill_data = $skill_profile->save($params); + } if (!empty($skill_data)) { echo 1; } else { diff --git a/main/inc/lib/skill.lib.php b/main/inc/lib/skill.lib.php index adaad5630d..d39e818177 100755 --- a/main/inc/lib/skill.lib.php +++ b/main/inc/lib/skill.lib.php @@ -31,6 +31,20 @@ class SkillProfile extends Model $profiles = Database::store_result($result, 'ASSOC'); return $profiles; } + + /** + * This function is for editing profile info from profile_id. + * @param int $profileId + * @param string $name + * @param string $description + */ + + public function UpdateProfileInfo($profileId, $name, $description) + { + $sql = "UPDATE $this->table SET `name` = '$name', `description` = '$description' WHERE id = $profileId "; + $result = Database::query($sql); + return $result; + } public function save($params, $show_query = false) { @@ -58,6 +72,7 @@ class SkillRelProfile extends Model public function __construct() { $this->table = Database::get_main_table(TABLE_MAIN_SKILL_REL_PROFILE); + $this->tableProfile = Database::get_main_table(TABLE_MAIN_SKILL_PROFILE); } public function get_skills_by_profile($profile_id) @@ -71,8 +86,20 @@ class SkillRelProfile extends Model } return $return_array; } -} + /** + * This function is for getting profile info from profile_id. + * @param int $profileId + */ + + public function getProfileInfo($profileId) + { + $sql = "SELECT * FROM $this->table p INNER JOIN $this->tableProfile pr ON(pr.id = p.profile_id) WHERE p.profile_id = $profileId "; + $result = Database::query($sql); + $profileData = Database::fetch_array($result, 'ASSOC'); + return $profileData; + } +} class SkillRelSkill extends Model { public $columns = array('skill_id', 'parent_id', 'relation_type', 'level'); diff --git a/main/template/default/skill/skill_wheel.js.tpl b/main/template/default/skill/skill_wheel.js.tpl index 74de28a41b..fd5b2d4183 100755 --- a/main/template/default/skill/skill_wheel.js.tpl +++ b/main/template/default/skill/skill_wheel.js.tpl @@ -180,10 +180,16 @@ function set_skill_style(d, attribute, searched_skill_id) { } //4. Blue - if user achieved that skill - if (d.achieved) { - return_fill = '#3A87AD'; - //return_stroke = '#FCD23A'; - } + //var skill = false; + $.ajax({ + url: url+'&a=get_user_skill&profile_id='+d.id, + async: false, + success: function(skill) { + if (skill == 1) { + return_fill = '#3A87AD'; + } + } + }); switch (attribute) { case 'fill': @@ -490,7 +496,7 @@ function load_nodes(load_skill_id, main_depth, extra_parent_id) { //.size([1, 2]) .value(function(d) { //return 5.8 - d.depth; - //When having more than 4 children seems that the code above doesn't work + //When having more than 4 children seems that the code above doesnt work return 1; }); diff --git a/main/template/default/skill/skill_wheel.tpl b/main/template/default/skill/skill_wheel.tpl index adbdcb045f..5733b60223 100755 --- a/main/template/default/skill/skill_wheel.tpl +++ b/main/template/default/skill/skill_wheel.tpl @@ -285,7 +285,8 @@ $(document).ready(function() { /* Click in profile */ $("#saved_profiles").on("click", "a.load_profile", function() { - profile_id = $(this).attr('rel'); + profile_id = $(this).attr('rel'); + $('#profile_id').attr('value',profile_id); $.ajax({ url: '{{ url }}&a=get_skills_by_profile&profile_id='+profile_id, success:function(json) { @@ -372,16 +373,29 @@ $(document).ready(function() { load_nodes(0, main_depth); function open_save_profile_popup() { + var profileId = $("#profile_id").val(); + $.ajax({ + url: '{{ url }}&a=get_profile&profile_id='+profileId, + success:function(data) { + if (data) { + var obj = jQuery.parseJSON (data); + $("#name_profile").attr('value', obj.name); + $("#description_profile").attr('value', obj.description); + } + } + }); + $("#dialog-form-profile").dialog({ buttons: { "{{ "Save"|get_lang }}" : function() { - var params = $("#save_profile_form").serialize(); + var name = $("#name_profile").val(); + var description = $("#description_profile").val(); var skill_list = return_skill_list_from_profile_search(); skill_list = { 'skill_id' : skill_list }; skill_params = $.param(skill_list); $.ajax({ - url: '{{ url }}&a=save_profile&'+params+'&'+skill_params, + url: '{{ url }}&a=save_profile&name='+name+'&description='+description+'&'+skill_params+'&profile='+profileId, success:function(data) { if (data == 1 ) { update_my_saved_profiles(); @@ -391,15 +405,17 @@ $(document).ready(function() { } $("#dialog-form-profile").dialog("close"); - $("#name").attr('value', ''); - $("#description").attr('value', ''); + $("#name_profile").attr('value', ''); + $("#description_profile").attr('value', ''); + $("#profile_id").attr('value', '0'); } }); } }, close: function() { - $("#name").attr('value', ''); - $("#description").attr('value', ''); + $("#name_profile").attr('value', ''); + $("#description_profile").attr('value', ''); + $("#profile_id").attr('value', '0'); } }); $("#dialog-form-profile").dialog("open"); @@ -547,17 +563,18 @@ $(document).ready(function() {