<commit_before><?php

/*
All Emoncms code is released under the GNU Affero General Public License.
See COPYRIGHT.txt and LICENSE.txt.

---------------------------------------------------------------------
Emoncms - open source energy visualisation
Part of the OpenEnergyMonitor project:
http://openenergymonitor.org
*/

// no direct access
defined('EMONCMS_EXEC') or die('Restricted access');

global $path, $org;

$languages = get_available_languages();
$roles = get_available_roles();
$organisations= $org->list_orgnames();

function languagecodetotext()
{
    _('es_ES');
    _('fr_FR');
    _('en_EN');
    _('nl_NL');
    _('nl_BE');
    _('da_DK');
    _('it_IT');
    _('cy_GB');
}

function get_available_roles()
{
    return array(
        '0'=>_('lambda'),
        '1'=>_('System administrator'),
        '3'=>_('organisation admin'),
        '4'=>_('designer'),
        '5'=>_('viewer')
        );
}


?>
<script type="text/javascript" src="<?php echo $path; ?>Modules/user/profile/profile.js"></script>
<script type="text/javascript" src="<?php echo $path; ?>Modules/user/profile/md5.js"></script>
<script type="text/javascript" src="<?php echo $path; ?>Modules/user/user.js"></script>
<script type="text/javascript" src="<?php echo $path; ?>Lib/listjs/list.js"></script>

<div class="row">

    <div class="col-md-4">
        <h3><?php echo _('My account'); ?></h3>

        <div id="account">

            <span class="text-muted"><?php echo _('Username'); ?></span>
            <span id ="edit-username" style="float:right; display:inline;" class='glyphicon glyphicon-pencil'  title = <?php echo _('Edit'); ?>></span>
            <span id ="save-username" style="float:right; display:none;" class='glyphicon glyphicon-floppy-save'  title = <?php echo _('Edit'); ?>></span>

            <p>
                <div id="username-view" style="display:inline">
                    <span class="username"></span>
                </div>
                <div id="edit-username-form" style="display:none">
                    <input class="username form-control" type="text" size ="40">
                </div>
            </p>
            <div id="change-username-error" class="alert-danger" style="display:none; width:100%"></div> 


            <span class="text-muted"><?php echo _('Email'); ?></span>
            <span id ="edit-email" style="float:right; display:inline;" class='glyphicon glyphicon-pencil'  title = <?php echo _('Edit'); ?>></span>
            <span id ="save-email" style="float:right; display:none;" class='glyphicon glyphicon-floppy-save'  title = <?php echo _('Edit'); ?>></span>
            <p>
                <div id="email-view" style="display:inline">
                    <span class="email"></span>
                </div>
                <div id="edit-email-form" style="display:none">
                    <input class="email form-control" type="email" size="40">
                </div>
            </p>
            <div id="change-email-error" class="alert-danger" style="display:none; width:100%"></div> 

            <p>
                <span class="text-muted"><?php echo _('Write API Key'); ?> </span>
                <!--<a id="newapikeywrite" >new</a>-->
                <span class="writeapikey btn btn-warning"></span>
            </p>
            <p>
                <span class="text-muted"><?php echo _('Read API Key'); ?> </span>
                <!--<a id="newapikeyread" >new</a>-->
                <span class="readapikey btn btn-warning"></span>
            </p>



            <p>
                <a id="changedetails"><?php echo _('Change Password'); ?></a>
            </p>
            <div id="password-changed" class="alert text-success" style="display:none"><?php echo _('Password is updated!'); ?></div>

        </div>

        <div id="change-password-form" style="display:none">
            <div  class="form-group">
                <label for="oldpassword" class="text-muted"><?php echo _("Current password"); ?></label>
                <input id="oldpassword" type="password" class="form-control" placeholder="'<?php echo _("type Current password"); ?>'"/>
            </div>
            <div  class="form-group">
                <label for="newpassword" class="text-muted"><?php echo _("New password"); ?></label>
                <input id="newpassword" type="password" class="form-control" placeholder="'<?php echo _("type New password"); ?>'"/>
            </div>
            <div  class="form-group">
                <label for="repeatnewpassword" class="text-muted"><?php echo _("Repeat new password"); ?></label>
                <input id="repeatnewpassword" type="password" class="form-control" placeholder="'<?php echo _("retype New password"); ?>'"/>
            </div>
            <div id="change-password-error" class="alert alert-danger" style="display:none;"><?php echo _('Passwords do not match'); ?></div>
            <input id="change-password-submit" type="submit" class="btn btn-primary active" value="<?php echo _('Save'); ?>" />
            <input id="change-password-cancel" type="submit" class="btn" value="<?php echo _('Cancel'); ?>" />
        </div>


    </div>



    <div class="col-md-7">
        <h3><?php echo _('My Profile'); ?></h3>
        <div id="table"></div>
    </div>

</div>

<script>

var path = "<?php echo $path; ?>";
var lang = <?php echo json_encode($languages); ?>;
var role = <?php echo json_encode($roles); ?>;
var orgs = <?php echo json_encode($organisations); ?>

list.data = user.get();

$(".writeapikey").html(list.data.apikey_write);
$(".readapikey").html(list.data.apikey_read);

// Need to add an are you sure modal before enabling this.
// $("#newapikeyread").click(function(){user.newapikeyread()});
// $("#newapikeywrite").click(function(){user.newapikeywrite()});

var currentlanguage = list.data.language;

list.fields = {
    'gravatar' :{ 'title':"<?php echo _('Gravatar'); ?>", 'type':'gravatar'},
    'name'     :{ 'title':"<?php echo _('Name'); ?>", 'type':'text','tooltip':'Use letters (a-z) only, accented characters are allowed!'},
    'location' :{ 'title':"<?php echo _('Location'); ?>", 'type':'text','tooltip':'Use letters (a-z) only, accented characters are allowed!'},
    'timezone' :{ 'title':"<?php echo _('Timezone'); ?>", 'type':'timezone','tooltip':'Choose your local time offset to UTC'},
    'language' :{ 'title':"<?php echo _('Language'); ?>", 'type':'select','tooltip':'System available languages', 'options':lang},
    'bio'      :{ 'title':"<?php echo _('Bio'); ?>", 'type':'text'},
    'orgid'    :{ 'title':"<?php echo _('Organisation'); ?>", 'type':'tblselect','tooltip':'Associate user to an Organisation', 'options':orgs},
    'admin'    :{ 'title':"<?php echo _('User role'); ?>", 'type':'idselect','tooltip':'Specify the user role', 'options':role},
};
$(startprofile);
list.init();

$("#table").bind("onSave", function(e){
    user.set(list.data);<commit_msg>make profile.php fields tooltips translatable<commit_after><?php

/*
All Emoncms code is released under the GNU Affero General Public License.
See COPYRIGHT.txt and LICENSE.txt.

---------------------------------------------------------------------
Emoncms - open source energy visualisation
Part of the OpenEnergyMonitor project:
http://openenergymonitor.org
*/

// no direct access
defined('EMONCMS_EXEC') or die('Restricted access');

global $path, $org;

$languages = get_available_languages();
$roles = get_available_roles();
$organisations= $org->list_orgnames();

function languagecodetotext()
{
    _('es_ES');
    _('fr_FR');
    _('en_EN');
    _('nl_NL');
    _('nl_BE');
    _('da_DK');
    _('it_IT');
    _('cy_GB');
}

function get_available_roles()
{
    return array(
        '0'=>_('lambda'),
        '1'=>_('System administrator'),
        '3'=>_('organisation admin'),
        '4'=>_('designer'),
        '5'=>_('viewer')
        );
}


?>
<script type="text/javascript" src="<?php echo $path; ?>Modules/user/profile/profile.js"></script>
<script type="text/javascript" src="<?php echo $path; ?>Modules/user/profile/md5.js"></script>
<script type="text/javascript" src="<?php echo $path; ?>Modules/user/user.js"></script>
<script type="text/javascript" src="<?php echo $path; ?>Lib/listjs/list.js"></script>

<div class="row">

    <div class="col-md-4">
        <h3><?php echo _('My account'); ?></h3>

        <div id="account">

            <span class="text-muted"><?php echo _('Username'); ?></span>
            <span id ="edit-username" style="float:right; display:inline;" class='glyphicon glyphicon-pencil'  title = <?php echo _('Edit'); ?>></span>
            <span id ="save-username" style="float:right; display:none;" class='glyphicon glyphicon-floppy-save'  title = <?php echo _('Edit'); ?>></span>

            <p>
                <div id="username-view" style="display:inline">
                    <span class="username"></span>
                </div>
                <div id="edit-username-form" style="display:none">
                    <input class="username form-control" type="text" size ="40">
                </div>
            </p>
            <div id="change-username-error" class="alert-danger" style="display:none; width:100%"></div> 


            <span class="text-muted"><?php echo _('Email'); ?></span>
            <span id ="edit-email" style="float:right; display:inline;" class='glyphicon glyphicon-pencil'  title = <?php echo _('Edit'); ?>></span>
            <span id ="save-email" style="float:right; display:none;" class='glyphicon glyphicon-floppy-save'  title = <?php echo _('Edit'); ?>></span>
            <p>
                <div id="email-view" style="display:inline">
                    <span class="email"></span>
                </div>
                <div id="edit-email-form" style="display:none">
                    <input class="email form-control" type="email" size="40">
                </div>
            </p>
            <div id="change-email-error" class="alert-danger" style="display:none; width:100%"></div> 

            <p>
                <span class="text-muted"><?php echo _('Write API Key'); ?> </span>
                <!--<a id="newapikeywrite" >new</a>-->
                <span class="writeapikey btn btn-warning"></span>
            </p>
            <p>
                <span class="text-muted"><?php echo _('Read API Key'); ?> </span>
                <!--<a id="newapikeyread" >new</a>-->
                <span class="readapikey btn btn-warning"></span>
            </p>



            <p>
                <a id="changedetails"><?php echo _('Change Password'); ?></a>
            </p>
            <div id="password-changed" class="alert text-success" style="display:none"><?php echo _('Password is updated!'); ?></div>

        </div>

        <div id="change-password-form" style="display:none">
            <div  class="form-group">
                <label for="oldpassword" class="text-muted"><?php echo _("Current password"); ?></label>
                <input id="oldpassword" type="password" class="form-control" placeholder="'<?php echo _("type Current password"); ?>'"/>
            </div>
            <div  class="form-group">
                <label for="newpassword" class="text-muted"><?php echo _("New password"); ?></label>
                <input id="newpassword" type="password" class="form-control" placeholder="'<?php echo _("type New password"); ?>'"/>
            </div>
            <div  class="form-group">
                <label for="repeatnewpassword" class="text-muted"><?php echo _("Repeat new password"); ?></label>
                <input id="repeatnewpassword" type="password" class="form-control" placeholder="'<?php echo _("retype New password"); ?>'"/>
            </div>
            <div id="change-password-error" class="alert alert-danger" style="display:none;"><?php echo _('Passwords do not match'); ?></div>
            <input id="change-password-submit" type="submit" class="btn btn-primary active" value="<?php echo _('Save'); ?>" />
            <input id="change-password-cancel" type="submit" class="btn" value="<?php echo _('Cancel'); ?>" />
        </div>


    </div>



    <div class="col-md-7">
        <h3><?php echo _('My Profile'); ?></h3>
        <div id="table"></div>
    </div>

</div>

<script>

var path = "<?php echo $path; ?>";
var lang = <?php echo json_encode($languages); ?>;
var role = <?php echo json_encode($roles); ?>;
var orgs = <?php echo json_encode($organisations); ?>

list.data = user.get();

$(".writeapikey").html(list.data.apikey_write);
$(".readapikey").html(list.data.apikey_read);

// Need to add an are you sure modal before enabling this.
// $("#newapikeyread").click(function(){user.newapikeyread()});
// $("#newapikeywrite").click(function(){user.newapikeywrite()});

var currentlanguage = list.data.language;

list.fields = {
    'gravatar' :{ 'title':"<?php echo _('Gravatar'); ?>", 'type':'gravatar'},
    'name'     :{ 'title':"<?php echo _('Name'); ?>", 'type':'text','tooltip':"<?php echo _('Use letters (a-z) only, accented characters are allowed!')?>"},
    'location' :{ 'title':"<?php echo _('Location'); ?>", 'type':'text','tooltip':"<?php echo _('Use letters (a-z) only, accented characters are allowed!')?>"},
    'timezone' :{ 'title':"<?php echo _('Timezone'); ?>", 'type':'timezone','tooltip':"<?php echo _('Choose your local time offset to UTC')?>"},
    'language' :{ 'title':"<?php echo _('Language'); ?>", 'type':'select','tooltip':"<?php echo _('System available languages')?>", 'options':lang},
    'bio'      :{ 'title':"<?php echo _('Bio'); ?>", 'type':'text'},
    'orgid'    :{ 'title':"<?php echo _('Organisation'); ?>", 'type':'tblselect','tooltip':"<?php echo _('Associate user to an Organisation')?>", 'options':orgs},
    'admin'    :{ 'title':"<?php echo _('User role'); ?>", 'type':'idselect','tooltip':"<?php echo _('Specify the user role')?>", 'options':role},
};
$(startprofile);
list.init();

$("#table").bind("onSave", function(e){
    user.set(list.data);
{'fraction_non_alphanumeric': 0.21855773358134212, 'fraction_numerical': 0.003147803691515238, 'mean_word_length': 2.9069312465064283, 'pattern_counts': {'":': 0, '<': 289, '<?xml version=': 0, '>': 301, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2113664', 'n_tokens_mistral': 4336, 'n_tokens_neox': 4209, 'n_words': 965}